Java code example (5)

Source: Internet
Author: User

1 /**2 * Demand Analysis: Input 5 students from the keyboard to a certain course of the written test results, and to find out five results of the overall score and average score3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test05;7 8 ImportJava.util.Scanner;9 Ten  Public classHs_array1 { One  A      Public Static voidMain (string[] args) { -         //TODO auto-generated Method Stub -System.out.println ("Please enter the written results of 5 students:"); the          -         DoubleSum=0; -         Doubleavg; -         int[] scores =New int[6]; +Scanner input=NewScanner (system.in); -         //Enter 5 results +          for(inti=0;i<5;i++){ A              atscores[i]=input.nextint (); -         } -         //sum -          for(intj=0;j<5;j++){ -sum=sum+Scores[j]; -         } inSystem.out.println ("Total:" +sum); -         //Average score toAvg=sum/5; +System.out.println ("Average score:" +avg);  -     } the}
1 /**2 * Requirements Analysis: Input from the keyboard 5 students a course of written test results,3 * and to find the highest score, the lowest score and the average score of five results4  * @authorChenyanlong5 * Date: 2017/10/146  */7  Packagecom.hp.test05;8 9 ImportJava.util.Scanner;Ten  One  Public classHs_array2 { A  -      Public Static voidMain (string[] args) { -          the         int[] scores=New int[5]; -         intSum=0; -        -         Doubleavg; +System.out.println ("Please enter 5 results"); -          +Scanner input=NewScanner (system.in); A          for(inti=0;i<scores.length;i++){            atscores[i]=input.nextint (); -         } -         //Total , highest score, lowest score -         intMax=scores[0]; -         intMin=scores[0]; -          for(intj=0;j<scores.length;j++){ in             // Total -Sum + =Scores[j]; to             //Minimum score +             if(scores[j]<min) { -min=Scores[j]; the             } *             //Minimum score $             if(scores[j]>max) {Panax Notoginsengmax=Scores[j]; -             } the         } +avg=sum/scores.length; ASystem.out.println ("Total:" +sum); theSystem.out.println ("Highest score:" +max); +System.out.println ("Lowest score:" +min); -System.out.println ("Average score:" +avg); $              $     } -}
1 /**2 * Demand Analysis: Use a two-dimensional array to store three class students ' scores and calculate the total score of three class students3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test05;7 8 Importjava.util.Arrays;9 ImportJava.util.Scanner;Ten  One  Public classHs_array3 { A  -      Public Static voidMain (string[] args) { -          the         int[] array=New int[][]{{2,1},{2,1,3},{2,1}}; -          for(inti=0;i<array.length;i++){ -String str= (i+1) + "class"; - Arrays.sort (Array[i]); +System.out.println (str+ "after sorting"); -              for(intj=0;j<array[i].length;j++){ + System.out.println (Array[i][j]); A             } at         } -     } -}
1 /**2 * Demand Analysis: Use a two-dimensional array to store three class students ' scores, and to sort the scores of three class students3  * @authorChenyanlong4 * Date: 2017/10/145  */6  Packagecom.hp.test05;7 8 ImportJava.util.Scanner;9 Ten  Public classHs_array4 { One  A      Public Static voidMain (string[] args) { -          -         int[] array=New int[][]{{1,2},{1,2,3},{1,2}}; the          -          for(inti=0;i<array.length;i++){ -String str= (i+1) + "class"; -             intTotal=0; +              for(intj=0;j<array[i].length;j++){ -Total +=array[i][j];//Score Summary +             } ASystem.out.println (str+ "total:" +Total ); at         } -          -         -     } -}

Java code example (5)

Related Article

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.