Q.22 Write a program that inputs 3-digit number and displays its digit in separate three lines.

public static void main(String[] args) {

Scanner x=new Scanner(System.in);

int n,a,b;

System.out.println(“Enter 3 digit number”);

n=x.nextInt();

a=n/100;

n=n%100;

b=n/10;

n=n%10;

System.out.println(a);

System.out.println(b);

System.out.println(n);

}

Output:

run:

Enter 3 digit number

234

2

3

4

BUILD SUCCESSFUL (total time: 4 seconds)

Leave a Reply

Your email address will not be published. Required fields are marked *