java-- any number keyboard input summing

Thinking, I counted the keyboard input into an array, and then summed convenient array

com.test.day01 Package Penalty for; 

Import java.util.Scanner; 

public  class the Test {
     public  static  void main (String [] args) { 
        . System OUT .println ( " Please enter the five students score " );
         // keyboard input summing any parameter 
        Scanner SC = new new Scanner (the System. in );
         // create an array of length 5 
        int [] = scoer new new  int [ 5 ];
         int SUM = 0 ;
         // iterate 
        for ( int I =0 ; I <scoer.length; I ++ ) { 
            the System. OUT .println ( " input section " + (I + . 1 ) + " bit student grades " );
             // keyboard input 
            scoer [I] = sc.nextInt () ;
             // summing 
            + = SUM scoer [I]; 
        } 
        the System. OUT .println ( " the Input SUM scoer: " + SUM);         
        }     
    }

Define an array to store three students calculate their total score

Package com.test.day01; 

Import java.util.Scanner; 

public  class the Test {
     public  static  void main (String [] args) {
         // definition of an array, stores three participants, the preparation method of calculating the total score of the student. 
        int [] = ARR new new  int [] {3,4, 5 };
         int SUM = 0 ;
         for ( int I = 0; I <arr.length; I ++ ) { 
            SUM + = ARR [I]; 
        } 
        the System.out .println (SUM); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/yaojun3/p/11504422.html