0

if a five-digit number is input through the keyboard, write a program to reverse the number???

plz solve and also explain it....

11th Oct 2016, 4:47 AM
Javed
Javed - avatar
4 Réponses
+ 2
lets say the number entered is 12345... long Value = scanner.nextLong(); String convertValue = Long.toString(Value); StringBuffer buffer = new StringBuffer(); for(int i = convertValue.length()-1; i >=0; i--){ buffer.append(convertValue.charAt(i)); } String finalAns = new String(buffer); long finalAnswer = Long.parseLong(finalAns); System.out.println(finalAnswer);
11th Oct 2016, 7:56 AM
Ousmane Diaw
+ 1
import java.util.Scanner; class ReverseNumberWhile { public static void main(String args[]) { int num=0; int reversenum =0; System.out.println("Input your number and press enter: "); //This statement will capture the user input Scanner in = new Scanner(System.in); //Captured input would be stored in number num num = in.nextInt(); //While Loop: Logic to find out the reverse number while( num != 0 ) { reversenum = reversenum * 10; reversenum = reversenum + num%10; num = num/10; } System.out.println("Reverse of input number is: "+reversenum); } } I feel its best
20th Oct 2016, 7:29 AM
DAMERA NIKHIL
0
I'm beginner. so I can't understand this way, plzz solve a simple way and explain loop.
11th Oct 2016, 5:54 PM
Javed
Javed - avatar
0
There are many ways to do this, I think that is one simple one, there is not really an loop for it!
15th Oct 2016, 10:25 AM
Finnt730
Finnt730 - avatar