我是新来的Java和我试图做一个程序,要求用户输入:如何获取用户输入的最小值和最大值? (JAVA)
- 学生(它必须是1-35个)。我设法做到了这一点。
- 每名学生的年级(0-100)。我设法做到了这一点,但如果有人介绍例如200,系统会通知这是不允许的,但变量仍然会影响成绩的平均值(我怎样才能删除最后插入的变量?)。
- 最后我想给出我设法做的一个平均水平,但我找不到一种方法来显示最高成绩和最低成绩。
public class ExtraClase {
public static void main(String[] args) {
Estudiantes estudiantes = new Estudiantes();
estudiantes.numeroEstudiantes();
}
}
public class Estudiantes {
public void numeroEstudiantes() {
System.out.print("Introduzca numero de estudiantes: ");
Scanner cantidad = new Scanner(System.in);
int number = cantidad.nextInt();
int i=1;
int total=0;
int promedio;
if(number>=1 && number<=35){
while(i<=number){
System.out.print("Ingrese la nota del 1-100: ");
Scanner nota = new Scanner(System.in);
int note = nota.nextInt();
if(note>=1 && note<=100) {
}else {
//como elimino la ultima nota introducida
System.out.println("Ingrese valor entre 1 y 100.");
number++;
}
total=total+note;
i++;
}
}else {
System.out.println("Digite numero entre 1 y 35.");
}
promedio=total/number;
System.out.println("El promedio de notas es: "+promedio);
System.out.println("La nota mas alta es: ");
System.out.println("La nota mas baja es: ");
}
}
这工作,非常感谢! –
很高兴帮助。 –