Write a java program to print reverse of given no. (U can use only these - if, if-else, do-while, while, for, switch case)
Answers
Answered by
1
importjava.util.scanner;
class reverse
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n,d=0;r=0;
System.out.print("enter the number");
n=sc.nextInt();
while(n>0);
{
d=n/10;
r=r*10+d;
n=n%10
}
if(n==r)
system.out.print("the reverse number is"+r);
}
}
class reverse
{
public static void main(String args[])
{
Scanner sc = new Scanner (System.in);
int n,d=0;r=0;
System.out.print("enter the number");
n=sc.nextInt();
while(n>0);
{
d=n/10;
r=r*10+d;
n=n%10
}
if(n==r)
system.out.print("the reverse number is"+r);
}
}
Answered by
2
import java.util.Scanner;
class ReverseNumber
{
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter the number to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while( n != 0 )
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of entered number is "+reverse);
}
}
If this is helpful,plzzzzzzz mark as best:)
class ReverseNumber
{
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter the number to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while( n != 0 )
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of entered number is "+reverse);
}
}
If this is helpful,plzzzzzzz mark as best:)
AbhishekSPeter:
Works perfectly!! Thanks
Similar questions
English,
8 months ago
English,
8 months ago
Math,
1 year ago
Computer Science,
1 year ago
Computer Science,
1 year ago