Question: Write a java program that reads an integer (greater than 0 and less than 1000) from the console and flip digits of the number, using

Write a java program that reads an integer (greater than 0 and less than 1000) from the console and flip digits of the number, using the arithmetic operators / and %. The result of the flip operation should always be a three digit number. Please make sure that your program works for one, two, and three digit inputs.

I was able to right a program that reverses a number that is already declared but am having issues reversing an input.

package reverse;

class GFG

{

/* Iterative function to reverse

digits of num*/

static int reversDigits(int num)

{

int rev_num = 0;

while(num > 0)

{

rev_num = rev_num * 10 + num % 10;

num = num / 10;

}

return rev_num;

}

// Driver code

public static void main (String[] args)

{

int num = 4562;

System.out.println("Reverse of no. is "

+ reversDigits(num));

}

}

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!