Results 1 to 2 of 2
- 01-19-2011, 08:29 PM #1
Senior Member
- Join Date
- May 2010
- Posts
- 113
- 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 .
Please help me in good coding .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; }
- 01-19-2011, 09:23 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 13
- Rep Power
- 0
Convert the above into proper java but UNDERSTAND it. Look up the Java documentation for the String class and the Character class.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; }
Similar Threads
-
Separating the digits of given number
By lb2 in forum New To JavaReplies: 5Last Post: 09-09-2010, 05:29 AM -
reversing digits
By gandalf5166 in forum New To JavaReplies: 3Last Post: 03-06-2010, 04:34 PM -
Digits of an integer.
By Allgorythm in forum New To JavaReplies: 8Last Post: 01-01-2010, 02:34 AM -
split() by digits
By RobertF in forum New To JavaReplies: 2Last Post: 03-12-2009, 02:16 AM -
sum of digits depreciation
By jleas in forum New To JavaReplies: 13Last Post: 11-09-2008, 01:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks