Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
  1. #21
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Quote Originally Posted by Bgreen7887 View Post
    why am i getting compile error with this so far?
    :eek:
    Try
    System.out.println(jennifer.nextLine()); instead of System.out.println(jennifer.nextLine);

  2. #22
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default Parsing with scanner on strings..

    Obviously the default delimiter is the white spaces, is there a delimiter that would break the string into individual characters?

  3. #23
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    You can use the charAt() method for that, after you read in the entire String.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  4. #24
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    ok maybe better if i show you.. im trying to recieve a string and print each char on next line heres what i have so far , maybe you could write it up in puesucode and i'll try compile it
    Java Code:
    import java.util.Scanner;
    public class ap  {
    public static void main(String[]args)  { 
    
    String n;
    Scanner jennifer = new Scanner(System.in);
    System.out.println("Please enter a String");
    //jennifer.useDelimiter("");
    
    
    while (jennifer.hasNext()) {
    n = jennifer.next();
    System.out.println(n);
    
            }
    
         }
    }

  5. #25
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Maybe it would be best if you write down the output you're trying to get, to avoid any confusion. What I'm getting from you, is that you want the user to input a string, and then print out every individual character in a new line. If that's the case, the pseudocode would be:
    Java Code:
    prompt user for input
    store input in String variable
    for every index from 0 to strings length - 1
      print out character at current index using charAt()
      new line
    end loop
    If that's what you're trying to achieve, you don't need to use a scanner more than once.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  6. #26
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    ok im reading string class api right now , getting past 3rd line of your code.

  7. #27
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    I cannot get that for loop...ughhh

  8. #28
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Can you write a small snippet that has an array of 5 ints and use a for loop to print each array element in a separate line? Strings can be seen as arrays of chars, so the method of iterating through it is pretty much the same.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  9. #29
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    we haven't learned arrays yet only loops so im sure this is suppose to be done with loops.give me a sec i will try something else

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Guidance for SCJP
    By sairam in forum New To Java
    Replies: 1
    Last Post: 06-30-2010, 09:21 AM
  2. Guidance needed
    By Curtiz in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2010, 05:41 PM
  3. need guidance in component placement
    By rdtindsm in forum AWT / Swing
    Replies: 2
    Last Post: 05-10-2009, 04:14 PM
  4. Guidance in writing a compiler
    By Jeremy in forum Advanced Java
    Replies: 2
    Last Post: 11-28-2008, 11:25 PM
  5. Guidance
    By gizdev in forum New To Java
    Replies: 5
    Last Post: 09-07-2008, 07:14 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
  •