Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
In your code you initialize the scanner object as Scanner sc = sc. new Scanner(System.in); Should be Scanner sc = new Scanner(System.in); Your code also tries to initialize the Scanner object again.
6th Oct 2021, 3:09 PM
Paul K Sadler
Paul K Sadler - avatar
0
So you have two elements at index a and b in your array and you want to swap values. Use a temporary variable c. Save the contents of the array at index a to variable c. Then replace the content of the array at index a with the contents of the array at index b. Then replace the contents of the array at index b with temporary variable c. All done!
6th Oct 2021, 2:41 PM
Paul K Sadler
Paul K Sadler - avatar