Using jGrasp and the Software Development Kit, write a program in response to th
ID: 3662057 • Letter: U
Question
Using jGrasp and the Software Development Kit, write a program in response to the following prompt: Write a method, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit(12345) is 54321. Also, write a program to test your method. Submit your compiled Java code for this assignment, compress the .java file into a single .zip file. For additional details, refer to the Programming Problems Rubric in the Assignment Guidelines and Rubrics folder.
Explanation / Answer
Here is the java code
import java.util.Scanner;
class ReverseNumber
{
////////Static method which performs the reverse operation
public static int reverseIt(int n)
{
int reverse=0;
while( n != 0 )
{
reverse = reverse * 10;
reverse = reverse + n%10; // Divide n by 10 contineously untill n becomes less n becomes less zero and on each itertion
// Obtain its modulus to get digits at different decimal places
n = n/10;
}
return reverse;
}
public static void main(String args[])
{
int n;
System.out.println("Enter the number to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Reverse of entered number is "+reverseIt(n));
}
}
output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.