Java code example (4)

Source: Internet
Author: User
Tags stub

1 /**2 * Demand analysis: Calculate within 100 and, with while3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8  Public classHS_LOOP1 {9 Ten      Public Static voidMain (string[] args) { One         //TODO auto-generated Method Stub A        intI=1,sum=0; -         -         while(i<=100){ thesum=sum+i; -i++; -        } -System.out.println ("Within 100 and:" +sum); +     } -  +}
1 /**2 * Demand analysis: Calculate within 100 and, with while3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8  Public classHS_LOOP1 {9 Ten      Public Static voidMain (string[] args) { One         //TODO auto-generated Method Stub A        intI=1,sum=0; -         -         while(i<=100){ thesum=sum+i; -i++; -        } -System.out.println ("Within 100 and:" +sum); +     } -  +}
1 /**2 * Demand Analysis: Input 5 results to find the average score3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8 ImportJava.util.Scanner;9 Ten  Public classHS_LOOP3 { One  A      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub - String name; the         DoubleSum=0, score; -         DoubleAvg=0; -System.out.println ("Please Enter name:"); -          +Scanner input=NewScanner (system.in); -Name=Input.next (); +         //System.out.println (name); A          for(inti=1;i<=5;i++){ atSystem.out.print ("Please enter the results of the" +i+ "course in the 5-door lesson:"); -              -Scanner input2=NewScanner (system.in); -Score=input2.nextdouble (); -sum=sum+score; -         } inAvg=sum/5; -The average score of System.out.println (name+ ") is:" +avg); to     } +}
1 /**2 * Demand Analysis: Input 5 results for average score, you can enter more than one person3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8 ImportJava.util.Scanner;9 Ten  Public classHS_LOOP4 { One  A      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub -String letter=NULL; the          Do{ - String name; -             DoubleSum=0, score; -             DoubleAvg=0; +System.out.println ("Please Enter name:"); -              +Scanner input=NewScanner (system.in); AName=Input.next (); at             //System.out.println (name); -              for(inti=1;i<=5;i++){ -System.out.print ("Please enter the results of the" +i+ "course in the 5-door lesson:"); -                  -Scanner input2=NewScanner (system.in); -Score=input2.nextdouble (); insum=sum+score; -             } toAvg=sum/5; +The average score of System.out.println (name+ ") is:" +avg); -              theSystem.out.print ("Continue output?" ( y/n): "); *Scanner input3=NewScanner (system.in); $Letter=Input3.next ();Panax Notoginseng} while(Letter.equals ("Y") | | Letter.equals ("Y")); -SYSTEM.OUT.PRINTLN ("Input Complete"); the     } +}
1 /**2 * Demand Analysis: The use of break3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8 ImportJava.util.Scanner;9 Ten  Public classHS_LOOP5 { One  A      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub -          for(inti=1;i<10;i++){ the             if(i==5){ -System.out.println ("Jump Once"); -                 Continue;  -             } +System.out.println ("" +i); -         } +     } A}
1 /**2 * Demand Analysis: The use of break3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test04;7 8 ImportJava.util.Scanner;9 Ten  Public classHS_LOOP6 { One  A      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub -          for(inti=1;i<10;i++){ the             if(i==5){ -System.out.println ("Loop ahead End"); -                  Break;  -             } +System.out.println ("" +i); -         } +     } A}

Java code example (4)

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.