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

Printable View

• 01-19-2011, 09:29 PM
renu
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 .
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 .
• 01-19-2011, 10:23 PM
aspire1
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.