Java input
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Java input

  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Java input

    Hi i have a problem with the following code:

    <code>
    import java.util.Scanner;
    public class Woorden{
    public static void main (String[] argv){
    Scanner input = new Scanner(System.in);
    String zin;
    System.out.print("Zin ");
    if (input.hasNextLine()){
    while (input.hasNext()){
    System.out.println(input.next());
    }
    }
    }
    }
    </code>

    The program should promt the user for one input line and then print the elements of that line one at a time. However, the program does not stop. The input is entered by using keyboard + command line.

    Can anyone help me with this problem?

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,397

    Re: Java input

    However, the program does not stop.
    You need to add code that looks at the input and sees if the user has requested the program to stop.
    Otherwise it will continue to wait for the user to enter more data.

    Read the API doc for the Scanner class and its methods. Some of the methods "block" meaning the program waits at that instruction until there is input to process.
    Norm

  3. #3
    Join Date
    Sep 2010
    Posts
    21

    Re: Java input

    Quote Originally Posted by NielsNIO View Post
    Hi i have a problem with the following code:

    <code>
    import java.util.Scanner;
    public class Woorden{
    public static void main (String[] argv){
    Scanner input = new Scanner(System.in);
    String zin;
    System.out.print("Zin ");
    if (input.hasNextLine()){
    while (input.hasNext()){
    System.out.println(input.next());
    }
    }
    }
    }
    </code>

    The program should promt the user for one input line and then print the elements of that line one at a time. However, the program does not stop. The input is entered by using keyboard + command line.

    Can anyone help me with this problem?
    Can you give us an output that is supposed to be look like?

    do you want it to display like this?

    Ex.
    Zin <string value>
    Zin <string value>
    Zin <string value>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center