Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: sdtin/command-line

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    Default sdtin/command-line

    I hope this is the right board to post this query on.

    I am really new to Java and am struggling to differentiate between reading from stid and taking output from command line in putting it into a method input.

    Where a command line would give the output of 6 integers, ie: 26, 62, 82, 27, 0, 0
    and the opening of a method would be:

    int main (int firstNum, int secondNum, int thirdNum, int fourthNum, int fifthNum, int sixthNum)

    I would not know how to read the same numbers from stdin in a format such as:
    26 62
    82 27
    0 0

    Let alone taking these and inputting them into a method.

    I have tried searching for a good introduction for this, yet have failed to find something that explains the difference effectively.

    Again, I apologise if this is the wrong board, I only just started learning java as a hobbie this summer and it's all very new to me.

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: sdtin/command-line

    stdin in Java is routed to the input stream System.in
    The easiest way I know to read from stdin is use a Scanner object.

    public static void main(String[] args)
        Scanner reader = new Scanner(System.in);
        int num1 = reader.nextInt();
        System.out.println("num1 = " + num1);

    I'd recommend reading the The Java™ Tutorials, starting with the Covering the Basics section.

Similar Threads

  1. Replies: 10
    Last Post: September 16th, 2011, 07:49 PM
  2. jre version in command line
    By major in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 14th, 2011, 06:55 AM
  3. Run command line structure in Java
    By soheilz92 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: April 20th, 2011, 02:26 AM
  4. command line arguments
    By rizla in forum Member Introductions
    Replies: 3
    Last Post: December 12th, 2010, 11:14 PM
  5. [SOLVED] Command Line Argument Help
    By EmSaint in forum Loops & Control Statements
    Replies: 2
    Last Post: January 28th, 2010, 10:55 AM