[0703] a set of operations results in descending order, the value inserted

. 1  Package com.workprojects;
 2  
. 3  Import java.util.Scanner;
 . 4  
. 5  / ** 
. 6  * value inserted
 7  * score for a group of students 99,85,82,63,60} {
 8  * descending order, and then add a student grades, the number of columns results insertion, holding descending
 . 9  * 2019-07-03
 10  * @author L
 . 11  *
 12 is   * / 
13 is  public  class Work070302 {
 14      static Scanner SC = new new Scanner (the System.in);
 15      public  static  void main (String [] args) {
 16          int[] Scores = new new  int [. 6]; // define the length of the array 
. 17          Scores [0] = 99 ;
 18 is          Scores [. 1] = 85 ;
 . 19          Scores [2] = 82 ;
 20 is          Scores [. 3] = 63 is ;
 21 is          Scores [ . 4] = 60 ;
 22 is          System.out.println ( "Please enter the new score:" );
 23 is          int newScore = sc.nextInt ();
 24          int index = -1; // define the subscript refers to 
25          for ( int 0 = I; I <scores.length; I ++ ) {
 26 is              IF (newScore>Scores [I]) {
 27                  index = I;
 28                  BREAK ;
 29              }
 30          }
 31 is          System.out.println ( "insert index score is:" + index);
 32          for ( int I = scores.length - 2; I> = index; i--) { // the index shifter 
33 is              scores [I +. 1] = scores [I];
 34 is          }
 35          scores [index] = newScore;
 36          System.out.println ( "inserted achievement message is: " );
 37 [          for ( int I: Scores) {
 38 is             System.out.print(i+"\t");
39         }
40     }
41 }

 

Guess you like

Origin www.cnblogs.com/yanglanlan/p/11134047.html