Dremendo Tag Line

Reverse 3 digit number in Java

Input - Question 8

In this question, we will see how to input a three digit number in Java programming using the java input and reverse it. To know more about java input click on the java input lesson.

Q8) Write a program in Java to input a three digit number and reverse it.

Input: 289
Reverse: 982

Program

import java.util.Scanner;

public class Q8
{
    public static void main(String args[])
    {
        int n,fd,md,ld,rev;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a three digit number");
        n=sc.nextInt();
        fd=n/100;
        md=(n/10)%10;
        ld=n%10;
        rev=ld*100+md*10+fd;
        System.out.print("Reverse=" + rev);
    }
}

Output

Enter a three digit number
326
Reverse=623
video-poster