java编写简单例子 20
展开全部
public class Test {
public static void main(String[] args) throws Exception {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
int count = 0;
int total = 0;
while(true) {
System.out.print("输入整数,以-1作为结束符:");
byte[] b = new byte[10];
System.in.read(b);
int temp = Integer.parseInt((new String(b).trim()));
if(temp == -1) break;
if(temp > max) max = temp;
if(temp < min) min = temp;
total += temp;
count++;
}
System.out.println("最大值: " + max);
System.out.println("最小值: " + min);
System.out.println("平均值: " + ((double)total / (double)count));
}
}
public static void main(String[] args) throws Exception {
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
int count = 0;
int total = 0;
while(true) {
System.out.print("输入整数,以-1作为结束符:");
byte[] b = new byte[10];
System.in.read(b);
int temp = Integer.parseInt((new String(b).trim()));
if(temp == -1) break;
if(temp > max) max = temp;
if(temp < min) min = temp;
total += temp;
count++;
}
System.out.println("最大值: " + max);
System.out.println("最小值: " + min);
System.out.println("平均值: " + ((double)total / (double)count));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询