7 public class Swap { 8. public static void main(String[] args) { //initialize to hold value of user input for number int number; //use scanner to retrieve user input Scanner input = new...


Can you explain how the method works for swapDigitPairs method??


For each line, can you add a note explaining the purpose


7 public class Swap {<br>8.<br>public static void main(String[] args) {<br>//initialize to hold value of user input for number<br>int number;<br>//use scanner to retrieve user input<br>Scanner input = new Scanner(System.in);<br>//ask user for number to swap<br>System.out.print(
9) { 33 34 35 36 37 38 39 result += temp * 10 * (number % 10); number /= 10; result += temp * (number % 10); number /= 10; temp *= 100; } return result + temp * number; 11 12 13 14 15 } "/>
Extracted text: 7 public class Swap { 8. public static void main(String[] args) { //initialize to hold value of user input for number int number; //use scanner to retrieve user input Scanner input = new Scanner(System.in); //ask user for number to swap System.out.print("Please input a number to be swapped: "); //retrieves the input as an int number = input.nextInt(); //extra nextLine() method call to retrieve abandoned enter key input.nextLine(); //print the swapped number result System.out.print("The swapped result is: " + swapDigitPairs(number) 11 12 13 14 15 91 18 19 20 21 22 23 24 25 26 27 28 29 30 310 32 } public static int swapDigitPairs(int number) { //initialize the temporary value to save the result int result = 0; int temp = 1; while(number > 9) { 33 34 35 36 37 38 39 result += temp * 10 * (number % 10); number /= 10; result += temp * (number % 10); number /= 10; temp *= 100; } return result + temp * number; 11 12 13 14 15 }

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here