Java-operators and flow control statements, java operator statements
- Notes for siwtch statements:
- Continue: Skip the remaining statement in the loop body to execute the next loop
- Break: exit the specified loop and directly execute the code after the loop
- Use the logging tool class to obtain user input information
Example: receive the scores of 4 students in each of the three classes, calculate the average score of the students in each class, and print it out.
Package com. test; import java. util. example; // import tool class
Public class Demo2 {public static void main (String [] args) {custom input = new partition (System. in); // create the score object double score = 0; double avg = 0; for (int I = 1; I <= 3; I ++) {score = 0; avg = 0; for (int j = 1; j <= 4; j ++) {System. out. print ("Enter score:"); score = score + input. nextInt (); // receives and saves the value entered by the user's keyboard
} System. out. print ("total score:" + score); avg = score/4; System. out. println ("average score:" + avg );}}}