answersLogoWhite

0

public class StringReverseExample

{

public static void main(String[] args)

{

int num=1001;

int n=num, rev;

while(num!=0)

{

int d=num%10;

rev= (rev*10)+d;

num=num/10;

}

System.uot.println(rev);

}

}

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
JudyJudy
Simplicity is my specialty.
Chat with Judy
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
More answers

To reverse the digits, you mean? I would convert to a StringBuffer, and use the built-in reverse() method to reverse it.

If you want to program this yourself, because that is what a teacher wants, get the last digit and print it out (or add it to a string); then divide the number by 10, and again get the last digit of the result (which is the second-last digit from the original number), and continue until you have naught left. To get the last digit, use the "%" operator:

myNumber % 10

This will give you the remainder of the division by 10.

To reverse the digits, you mean? I would convert to a StringBuffer, and use the built-in reverse() method to reverse it.

If you want to program this yourself, because that is what a teacher wants, get the last digit and print it out (or add it to a string); then divide the number by 10, and again get the last digit of the result (which is the second-last digit from the original number), and continue until you have naught left. To get the last digit, use the "%" operator:

myNumber % 10

This will give you the remainder of the division by 10.

To reverse the digits, you mean? I would convert to a StringBuffer, and use the built-in reverse() method to reverse it.

If you want to program this yourself, because that is what a teacher wants, get the last digit and print it out (or add it to a string); then divide the number by 10, and again get the last digit of the result (which is the second-last digit from the original number), and continue until you have naught left. To get the last digit, use the "%" operator:

myNumber % 10

This will give you the remainder of the division by 10.

To reverse the digits, you mean? I would convert to a StringBuffer, and use the built-in reverse() method to reverse it.

If you want to program this yourself, because that is what a teacher wants, get the last digit and print it out (or add it to a string); then divide the number by 10, and again get the last digit of the result (which is the second-last digit from the original number), and continue until you have naught left. To get the last digit, use the "%" operator:

myNumber % 10

This will give you the remainder of the division by 10.

User Avatar

Wiki User

15y ago
User Avatar

class Reverse

{

public static void printReverse(int n)

{

int temp = n;

int rev = 0, b;

while ( n > 0 )

{

b = n % 10;

rev = rev * 10 + b;

n = n / 10;

}

System.out.println("The number is..." + temp);

System.out.println("The reverse of the number is..." + rev);

}

}

User Avatar

Wiki User

14y ago
User Avatar

class Reverse{

public static void main(String args[]){

int num=0,rem=0,rev=0;

Scanner sc=new Scanner(System.in);

System.out.println("ENTER THE NUMBER TO BE REVERSED:");

num=sc.nextInt();

do{

rem=num%10;

rev=rev+(rem*10);

num=num/10;

}while(num!=0);

System.out.println("REVERSE OF THE NUMBER IS:"+rev);

}

}

User Avatar

Wiki User

13y ago
User Avatar

To reverse the digits, you mean? I would convert to a StringBuffer, and use the built-in reverse() method to reverse it.

If you want to program this yourself, because that is what a teacher wants, get the last digit and print it out (or add it to a string); then divide the number by 10, and again get the last digit of the result (which is the second-last digit from the original number), and continue until you have naught left. To get the last digit, use the "%" operator:

myNumber % 10

This will give you the remainder of the division by 10.

User Avatar

Wiki User

15y ago
User Avatar

I suggest to convert the number to a String, or better directly to a StringBuffer, object. Then use the reverse() method of the StringBuffer class.


User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Program for print reverse string of given number in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you convert a number that consist of alphabet and number in reverse order?

To reverse a number, first convert the number to a string, then reverse the string. Given your number consists of alphanumeric characters, the number must already be a string so simply reverse the string: #include<string> using std::string; string reverse (const string& s) { string str {}; for (auto c : s) str.insert (str.begin(), c); return str; } int main () { std::cout << "Enter a number: "; string s {}; std::cin >> s; std::cout << "The number in reverse is: " << reverse (s); }


How to write A Java program to print number of digits in a given number?

One way to do this is to convert the number to a String, then use the corresponding String method to find out the length of the String.


2 Create a Console application that gets the a number as input from the user and it should be reversed?

//This function reverse any given string, except nullstatic string Reverse(string s) {char[] temp = s.ToCharArray();Array.Reverse(temp);return new string(temp);}//The main usagestring inputString = Console.ReadLine();Console.WriteLine(Reverse(inputString));


How do you write a program that outputs a given characters in reverse?

write the javascript code to display the reverse no. of given no. (e.g. 247 reverse of 742)


Write a java program to count the space from the given line?

.... String line = "This is example program with spaces"; String[] tokens = line.split(" "); System.out.println(tokens.length-1); .......