# Thread: Value should be 7 or 8 digits .If 8 digits, the last should be a character

1. Senior Member
Join Date
May 2010
Posts
119
Rep Power
0

## Value should be 7 or 8 digits .If 8 digits, the last should be a character

Hi

ANy one help me correcting the below method to get a solution for

School ID , must be 7 or 8 digits. If 8 digits , the last should be a character and you should truncate the number to 7 digits when passing it to the proc .

The code i wrote , is wrong , pls help me correct it to achieve the above request .
Java Code:
```private static String f_facilityID(Scanner scan) {
boolean loopUntilGoodNumber;
System.out.println("Enter Facility ID:");
String facilityID = scan.next();
int count = facilityID.length();
System.out.println("The count is :"+count);
if(count == 8){
loopUntilGoodNumber =isIntNumber(facilityID);
if(loopUntilGoodNumber ==  false){
facilityID = facilityID.substring(0,7);
}
}
return facilityID;
}
public static boolean isIntNumber(String scn1){
try{
Long.parseLong(scn1);
}catch(NumberFormatException nfe){
return false;
}
return true;
}```
Please help me in good coding .

2. Member
Join Date
Jan 2011
Posts
13
Rep Power
0
Java Code:
```public static boolean isValid ( String id)
{
let valid:= false
let len: = length of id

if( len > 6 && len < 9 )
{
try
convert substring( 0, 6 ) of id to integer
valid:= true
catch Exception

if( valid && len == 8 )
{
check if the character at id position 7 is a letter
and assign true or false to valid

}
}

return valid;

}```
Convert the above into proper java but UNDERSTAND it. Look up the Java documentation for the String class and the Character class.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•