Write a class ReverseNumber to accept the number and find the reverse of it.

0

Assignment: Module 03- Part 03

Write a class ReverseNumber to accept the number and find the reverse of it.

Write a class ReverseNumber to accept the number and find the reverse of it.

Input: 

Enter the number 456

Output:

654


import java.util.Scanner;

public class ReverseNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number: ");
        int num = sc.nextInt();
        int reverse = 0;
        
        while (num != 0) {
            int lastDigit = num % 10;
            reverse = reverse * 10 + lastDigit;
            num /= 10;
        }
        
        System.out.println("Reverse of the number: " + reverse);
    }
}   

Output:

Enter the number: 456
Reverse of the number: 654   

👉Write a class PrimeFinder to accept the number and find it is a prime number or not? Using control structures👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates