need help

Ask the user to enter the roll number.The roll number has to begin with IAD followed by some number
IAD 123
I have to store only the number.


  • u can use

    String roll = roll_number.substring(4);
    then roll is 123;

    IAD and space will not appear in case to roll

    then u can use roll to insert in Database.

  • import*;

    class Roll
    public static void main(String A[]) throws IOException
    BufferedReader br=new BufferedReader(new InputStreamReader(;
    String rno,roll;

    //Modify as needed....

    System.out.print("Enter Roll No. (IAD xxxx):");
    if(!rno.startsWith("IAD "))
    System.out.print("Invalid Input! Re-enter Roll No. (IAD xxxx):");
    roll=rno.substring(4);//for IAD 123 or rno.substring(3) for IAD123
    /* If you need the number representation of 'roll' you can use Integer.parseInt(roll);
    You can also use getChars() or getBytes() instead of substring(); as per your requirement.

    System.out.println( rno+" "+roll);

    Hope, this helps....!!!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!