Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions