Source: http://www.imooc.com/video/1628
New requirements:
Write Java program to receive three classes each four students of the Java results, and then calculate the average score of each class student
Tips:
Enter main plus Alt +/Enter, then enter
Public Static void Main (string[] args) { }
The source code is as follows:
1 PackageCom.imooc;2 ImportJava.util.Scanner;3 4 /*5 * Function: Realize the Java achievement of receiving four students from three classes, then calculate the average score of each class student6 * Knowledge points: Double circulation, outer loop control number of classes, Inner loop control number of students per class7 *8 */9 Public classDemo02 {Ten Public Static voidMain (string[] args) { One intclassnum=3;//Number of Classes A intstunum=4;//Number of students - Doublesum=0;//Total Score - Doubleavg=0;//average score of scores theScanner input=NewScanner (system.in); - - for(intI=1; I <= classnum; i++) {//Outer Loop controls the number of classes -SYSTEM.OUT.PRINTLN ("* * * * Please enter the" +i+ "class Grades * * * *"); +Sum=0; - for(intj=1;j<=stunum;j++) { +System.out.println ("Please enter" +j+ "Student's score:"); A intScore=input.nextint ();//get the input score atSum=sum+score;//Result summation - } -AVG = Sum/stunum;//calculate the average score -System.out.println ("+i+" class student's average divided into: "+avg); - } - in } -}
The results are as follows:
Please enter the 1th class score * ***The average of the 1th class students is divided into:82.75*** Please enter the grade of 2nd class * * * The average of the 2nd class students is divided into:81.0*** Please enter the 3rd class score * * *88 98 The average of 3rd class students is divided into:81.75
Experience Summary:
1. Identify requirements through analysis
2. Organize relevant knowledge points
3. Carding the implementation process
4. Solve the problem with "breakpoint tracking"
Web-android Engineer Beginner-5-5 Advanced Practice