Results 1 to 2 of 2
  1. #1
    danielwestjr is offline Member
    Join Date
    Oct 2008
    Posts
    3
    Rep Power
    0

    Exclamation Using the scanner class

    Im trying to scan a string from the user (System.in) and then use a delimiter to remove blank spaces and make the input one string eg.
    if the user enters:
    com puter,
    the output should be "computer"
    but Im having probs with the code;heres what i have so far:

    System.out.println(" Enter The Name for the Lab : ");

    if (labscan.hasNext());
    {
    lab1 = labscan.nextLine();

    labscan1 = new Scanner(lab1);
    //labscan1.useDelimiter(" ");

    while (labscan1.hasNext());
    labscan1.useDelimiter(" ");
    str = "";
    lab1 = labscan1.next() + str;
    labobj1.setName(lab1);
    System.out.println();
    }

    can u help me out please?

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default

    If you want to remove blank only means,you have to read the input by next() function and add the string.
    For example,
    s=sc.next();
    s1=sc.next();
    total=s+s1;
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Use of Scanner class and Delimiter
    By tjhodge in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 05:26 PM
  2. Scanner Class...
    By TheRocket in forum New To Java
    Replies: 5
    Last Post: 12-05-2008, 09:48 AM
  3. Scanner class question
    By Rgfirefly24 in forum New To Java
    Replies: 5
    Last Post: 04-25-2008, 12:41 AM
  4. Scanner class
    By ajaymenon.k in forum Advanced Java
    Replies: 1
    Last Post: 11-26-2007, 07:01 AM
  5. JDK 5.0 Scanner Class
    By Sircedric88 in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 06:55 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
  •