Howdy, Stranger!

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

Categories

need help

pinky16pinky16 Member Posts: 1
Ask the user to enter the roll number.The roll number has to begin with IAD followed by some number
Example
IAD 123
I have to store only the number.

Comments

  • krishbalodakrishbaloda Member Posts: 45
    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.


  • Avenger625Avenger625 Member Posts: 8
    import java.io.*;

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

    //Modify as needed....

    System.out.print("Enter Roll No. (IAD xxxx):");
    do{
    rno=br.readLine();
    if(!rno.startsWith("IAD "))
    System.out.print("Invalid Input! Re-enter Roll No. (IAD xxxx):");
    else{
    roll=rno.substring(4);//for IAD 123 or rno.substring(3) for IAD123
    break;
    /* 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.
    */
    }
    }while(true);

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


    Hope, this helps....!!!

Sign In or Register to comment.