Results 1 to 2 of 2
  1. #1
    renu is offline Senior Member
    Join Date
    May 2010
    Posts
    117
    Rep Power
    0

    Question 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. #2
    aspire1 is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Separating the digits of given number
    By lb2 in forum New To Java
    Replies: 5
    Last Post: 09-09-2010, 06:29 AM
  2. reversing digits
    By gandalf5166 in forum New To Java
    Replies: 3
    Last Post: 03-06-2010, 05:34 PM
  3. Digits of an integer.
    By Allgorythm in forum New To Java
    Replies: 8
    Last Post: 01-01-2010, 03:34 AM
  4. split() by digits
    By RobertF in forum New To Java
    Replies: 2
    Last Post: 03-12-2009, 03:16 AM
  5. sum of digits depreciation
    By jleas in forum New To Java
    Replies: 13
    Last Post: 11-09-2008, 02:37 PM

Posting Permissions

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