Results 1 to 4 of 4
  1. #1
    vendetta is offline Member
    Join Date
    Jan 2010
    Posts
    31
    Rep Power
    0

    Default standard input stream storing to a generic method?

    I am trying to read-in a string in Java. In C++ this function is 'cin". It basically prompts the user to input information.

    The spot I would like to store this is in a method called "add(E element)" where it stores the string. how would I bring up the prompt so the user types in a string to store the info to the method?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    how would I bring up the prompt so the user types in a string
    JOptionPane is a popular choice for getting user input.

    See the page
    How to Make Dialogs

  3. #3
    sathishsengg is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I think ,You want read input from keyboard ...
    This is sample to read Input from keyboard, use this to read and do ur stuff...
    Java Code:
    // should import java.io package...
    
    	try
    	{
    		DataInputStream dis=new DataInputStream(System.in);
    		String s=dis.readLine();	// To read String
    		int a=Integer.parseInt(s) 	// convert input string to int
    	}
    	catch(IOException ie)
    	{
    		....
    	}
    Last edited by sathishsengg; 01-29-2010 at 03:17 PM.

  4. #4
    vendetta is offline Member
    Join Date
    Jan 2010
    Posts
    31
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2009, 02:45 AM
  2. More than one input in one private method
    By rice in forum New To Java
    Replies: 0
    Last Post: 10-02-2009, 06:08 AM
  3. TCP/IP Client program halts at the read method of the stream
    By PradeepBadiger in forum Networking
    Replies: 0
    Last Post: 03-26-2009, 04:14 PM
  4. Replies: 1
    Last Post: 12-28-2008, 11:25 AM
  5. Replies: 2
    Last Post: 08-07-2007, 04:50 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
  •