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)