Question: Using jGRASP i want the code to run this program Reverse number revised Listing 6.2 (shown below, pg 277 in the text), is an example

Using jGRASP i want the code to run this program

Reverse number revised

Listing 6.2 (shown below, pg 277 in the text), is an example that demonstrates the use of a dowhile loop to reverse an integer number. Modify the program so that the reversal process is called from a value returning method instead of included in the main program. Use a value returning method that accepts the integer as a parameter and returns the reversed number.

import java.util.Scanner;

public class ReverseNumber

{

//-----------------------------------------------------------------

// Reverses the digits of an integer mathematically.

//-----------------------------------------------------------------

public static void main(String[] args)

{

int number, lastDigit, reverse = 0;

Scanner scan = new Scanner(System.in);

System.out.print("Enter a positive integer: ");

number = scan.nextInt();

//This part needs to go in its own method now ^_^

do {

lastDigit = number % 10;

reverse = (reverse * 10) + lastDigit;

number = number / 10;

} while (number > 0);

//Call your new method here (or within the output statement below)

System.out.println("That number reversed is " + reverse);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!