我是新來的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: ");
}
}
這工作,非常感謝! –
很高興幫助。 –