...里输入数据后控制台无法输出结果,并且控制台显示程序一直在运行_百 ...
发布网友
发布时间:2024-10-18 12:41
我来回答
共1个回答
热心网友
时间:2024-12-03 05:44
你的Java程序没有问题,没有输出是因为你没有输入分数,程序在运行等待你输入分数,并且以负数结束输入.
import java.util.Scanner;
public class dddd {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double highest = 0;
double lowest = 0;
double avg = 0;
int count = 0;
double total = 0;
double temp = 0;
int n = 0;
if ((temp = scan.nextDouble()) >= 0) {
highest = temp;
lowest = temp;
if (temp >= 60) {
count++;
}
n++;
total = total + temp;
}
do {
temp = scan.nextDouble();
if (temp < 0) {
break;
}
n++;
if (highest < temp) {
highest = temp;
}
if (lowest > temp) {
lowest = temp;
}
if (temp >= 60) {
count++;
}
total = total + temp;
} while (temp >= 0);
System.out.println("最高分: " + highest);
System.out.println("最低分: " + lowest);
System.out.println("平均分: " + total/n);
System.out.println("及格人数: " + count);
}
}
运行结果
50 60 70 80 99 100 -1
最高分: 100.0
最低分: 50.0
平均分: 76.5
及格人数: 5