首页上一页 1 下一页尾页 1 条记录 1/1页
尊敬的明日科技的老师
发表在Java图书答疑
2012-03-05
是否精华
是
否
版块置顶:
是
否
尊敬的明日科技的老师:
您好,下面这段程序是:从键盘输入一组成绩,统计90分以上的所占的百分比。我的做法是将键盘输入放到一个字节数组中,再将字节数组中的值转换为整型放到整形数组中,
m为大于等于90分的个数,输入的总数为10,n除10即为百分比。问题是:转换为int数组后,值变了,比如从键盘输入99,转换为int数组后,值变为56,
到底是怎么回事?该怎么改?特向您请教,打扰了,谢谢。
import java.io.IOException;
public class chengji {
/**
* @param args
* @throws IOException
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int m = 0;
int [] score = new int[10];
for(int i=0;i<10;i++){
byte [] chengji = new byte[20];
System.in.read(chengji);
score[i] = (int)chengji[i];
System.out.println(score[i]);
if(score[i]>90){
m++;
}
}
System.out.println(m/10*100.0+"%");
}
}
您好,下面这段程序是:从键盘输入一组成绩,统计90分以上的所占的百分比。我的做法是将键盘输入放到一个字节数组中,再将字节数组中的值转换为整型放到整形数组中,
m为大于等于90分的个数,输入的总数为10,n除10即为百分比。问题是:转换为int数组后,值变了,比如从键盘输入99,转换为int数组后,值变为56,
到底是怎么回事?该怎么改?特向您请教,打扰了,谢谢。
import java.io.IOException;
public class chengji {
/**
* @param args
* @throws IOException
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int m = 0;
int [] score = new int[10];
for(int i=0;i<10;i++){
byte [] chengji = new byte[20];
System.in.read(chengji);
score[i] = (int)chengji[i];
System.out.println(score[i]);
if(score[i]>90){
m++;
}
}
System.out.println(m/10*100.0+"%");
}
}