Home > Back-end >  Help!
Help!

Time:09-24

Java from the keyboard input number 10, and put it in a one-dimensional array, and then the top five elements and the five elements change: after the first element and the tenth element swaps, swaps, the second element and the ninth element, fifth and sixth element swaps, respectively, the output array value of each element and element value after the exchange, analysis: due to the subject requirement is to realize the fore and aft element swaps, so I can take with a temporary variable method to exchange elements,

CodePudding user response:

 Scanner input=new Scanner (System. In); 
Int nums=new int [] [10].
For (int I=0; I & lt; Nums. Length; I++) {
System. The out. Println (" please enter the first "+ (I + 1) +" number ");
Nums=input. [I] nextInt ();
}
Int temp=0;
For (int I=0; I & lt; Nums. Length/2; I++) {
Temp=nums [I];
Nums=nums [I] [nums. Length - I - 1);
Nums [nums. Length - I - 1]=temp;
}
System. The out. Println (Arrays. ToString (nums));

CodePudding user response:

reference 1st floor YangjulongTrue response:
 Scanner input=new Scanner (System. In); 
Int nums=new int [] [10].
For (int I=0; I & lt; Nums. Length; I++) {
System. The out. Println (" please enter the first "+ (I + 1) +" number ");
Nums=input. [I] nextInt ();
}
Int temp=0;
For (int I=0; I & lt; Nums. Length/2; I++) {
Temp=nums [I];
Nums=nums [I] [nums. Length - I - 1);
Nums [nums. Length - I - 1]=temp;
}
System. The out. Println (Arrays. ToString (nums));

Thank you, brother!