Java-operators and flow control statements, java operator statements

Source: Internet
Author: User

Java-operators and flow control statements, java operator statements

  • Operator priority:

  

  • Notes for siwtch statements:
  • For Loop
  • 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 );}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.