Results 1 to 2 of 2
  1. #1
    Gtrain is offline Member
    Join Date
    Aug 2009
    Rep Power

    Default Code streamlining

    Hey Guys,
    I am new to java and new to the board, so firstly hello!


    I am working on a project part of this is to validate a student id that needs to be of length 8 and the first seven chars will be digits and the 8th needs to be a letter. I have come up with this so far but i believe it could be a lot cleaner, it works however!! As i am typing this i now know that the 8th char whilst unable to be a digit, can be a symbol,, hmm how to go about this??

    Just wondering if you guys have any thoughts for me

    void checkStudentData(String studentID){
    if (studentID == null){
    while (studentID == null){
    try {
    Scanner sc = new Scanner(;
    System.out.print("Please enter student ID to check" +
    "\n ID must be 7 digits and 1 character\n");
    String sID =;
    if(String.valueOf(sID).trim().length() != 8)
    throw new Exception();
    else if (Character.isDigit(sID.charAt(7)))
    throw new Exception();
    int i;
    for ( i= 0; i<7; i++){
    studentID = sID;
    throw new Exception();

    catch(Exception e){
    System.out.println("Invalid Student ID");


  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    You say that you want to verify the code from client, once the client enter the code you want to check that it's in correct format. Is it?

    Such validations we can do easily using regular expressions. Or else in simple logic, like the code length should be 8, and the last digit should be a letter. Validation of the last digit can be done in this way, convert the digit to a number, if it's a letter or a symbol you comes with an exceptions, means it's not a number. Those trick things we can do sometimes, I'm doing it.

Similar Threads

  1. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 12:14 PM
  2. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  3. Why doesn't this code accept my code?
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 02:39 PM
  4. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 11:12 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 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