I wanted to get the mobile number from the user in java using scanner. When the user enters the number, he/she shouldn't be able to enter when the limit exceeds 10. Could anyone share how ?
long mobNo; Scanner s=new Scanner(System.in); mobNo=s.nextLong(); int length = (int)(Math.log10(mobNo)+1); if(length==10) System.out.println("Successfully entered !"); else System.out.println("Enter only 10 digits");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)