Home > Back-end >  For bosses to solve
For bosses to solve

Time:10-06

The while loop is used to implement the following topics: input n (indeterminate) the scores of the classmate, expressed as a "0" input end, if the input is negative, prompt result is wrong, records obtained by the sum of all grades sum, and the corresponding number n, calculate average scores avg, if avg<60, then output "grade point average is unqualified; Otherwise, output "average qualified",

CodePudding user response:

 

Import the Java. Math. BigDecimal;
Import the Java. Util. ArrayList;
Import the Java. Util. List;
import java.util.Scanner;

Public class T {

Public static void main (String [] args) {
List List=new ArrayList (a);
System. The out. Println (" both please enter the num: ");
Int sum=0;
Scanner scan=new Scanner(System.in);
While (true) {
String STR=scan. The next ();
Try {
Int num=Integer. The valueOf (STR);
If (num==0) {
break;
}
If (num & lt; 0 {
System. Out. Println (" grades input wrong ");
break;
}
List. The add (num);
The sum +=num;
} the catch (Exception e) {
e.printStackTrace();
}
}
For (int num: list) {
System. The out. Print (num + "");
}
System.out.println();
BigDecimal avg=new BigDecimal (sum). Divide (new BigDecimal (list. The size ())). SetScale (2);
If (avg.com pareTo (new BigDecimal (60)) & lt; 0 {
System. The out. Println (" result is unqualified ");
} else {
System. The out. Println (" passed ");
}
}
}

CodePudding user response:

22 is less than 0 why the break,
To continue should continue to the next round of cycle
  • Related