reverse number find in java loop
Answers
Answered by
1
public class ReverseNumberUsingFor {
private static Scanner sc;
public static void main(String[] args) {
int Number, Reminder, Reverse;
sc = new Scanner(System. in);
Number = sc. nextInt();
for(Reverse = 0; Number > 0; Number = Number/10) {
Reminder = Number %10;
Answered by
0
Answer:
import java.util.*;
class reverseNumber
{
static int reverse(int n)
{
int rev = 0;
while(n != 0)
{
int last = n % 10;
rev = rev * 10 + last;
n /= 10;
}
return rev;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number:");
int num = sc.nextInt();
System.out.println("The reverse of " + num + " is " + reverse(num));
}
}
Explanation:
Similar questions