Computer Science, asked by akshita287912, 11 months ago

How to input 4 digit number
in scanner class​

Answers

Answered by Tmmcbr
1

Answer:

import java.util.Scanner;

class Hi

{

void no()

{

Scanner sc = new Scanner(System.in);

System.out.println("Enter");

String a = sc.nextLine();

if(a.length()==4)

int b = Integer.parseInt(a)

else

System.out.println("Not a four digit no.");

}

}

Similar questions