public class ReverseNumberExample1
{
public static void main(String[] args)
{
int number = 987654, reverse = 0;
while(number != 0)
{
int remainder = number % 10;
reverse = reverse * 10 + remainder;
number = number/10;
}
System.out.println("The reverse of the given number is: " + reverse);
}
}
while(num != 0)
{
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
import java.util.*;
class reverse
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter String: ");
String str = sc.next();
char d;
String str2 = "";
int l = str.length();
for(int i = l-1; i >= 0; i--)
{
d = str.charAt(i);
str2 = str2 + d;
}
System.out.println(str2);
sc.close();
}
}
int rev= 0;
while(num > 9)
{
rev= rev*10 + num%10;
num/= 10;
}
class Main {
public static void main(String[] args) {
int num = 1234, reversed = 0;
System.out.println("Original Number: " + num);
// run loop until num becomes 0
while(num != 0) {
// get last digit from num
int digit = num % 10;
reversed = reversed * 10 + digit;
// remove the last digit from num
num /= 10;
}
System.out.println("Reversed Number: " + reversed);
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = input.nextInt();
int rev = 0;
while (num > 0) {
rev = rev * 10 + num % 10;
num /= 10;
}
System.out.println(rev);
}
import java.util.Scanner;
public class App1 {
public static void main(String[] args) {
Scanner scannerNum = new Scanner((System.in));
int number , sum = 0;
number = scannerNum.nextInt();
System.out.println("sum = " + sum);*/
int result = 0 , digit;
while(number != 0)
{
result *= 10;
digit = number % 10;
result += digit;
number = number / 10;
}
System.out.println("result = " + result);
}
}