I don't know how to input through windows command prompt












0















I made a simple program on java:



public class HelloWorld {

public static void main(Stringargs) {
System.out.print(" Hello World");
int n=Integer.parseInt(args[0]);
StdOut.println();
StdOut.print(n);
}
}


When I run the program through windows command prompt it just prints "Hello World" and the program ends, with no error messages, not waitting for me to input the integer. I don't know what I do wrong. Is there any trick I don't know?










share|improve this question













migrated from superuser.com Jan 18 at 22:10


This question came from our site for computer enthusiasts and power users.














  • 2





    Try to understand what each line does.

    – gronostaj
    Jan 18 at 19:51






  • 1





    Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

    – slhck
    Jan 18 at 19:57
















0















I made a simple program on java:



public class HelloWorld {

public static void main(Stringargs) {
System.out.print(" Hello World");
int n=Integer.parseInt(args[0]);
StdOut.println();
StdOut.print(n);
}
}


When I run the program through windows command prompt it just prints "Hello World" and the program ends, with no error messages, not waitting for me to input the integer. I don't know what I do wrong. Is there any trick I don't know?










share|improve this question













migrated from superuser.com Jan 18 at 22:10


This question came from our site for computer enthusiasts and power users.














  • 2





    Try to understand what each line does.

    – gronostaj
    Jan 18 at 19:51






  • 1





    Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

    – slhck
    Jan 18 at 19:57














0












0








0








I made a simple program on java:



public class HelloWorld {

public static void main(Stringargs) {
System.out.print(" Hello World");
int n=Integer.parseInt(args[0]);
StdOut.println();
StdOut.print(n);
}
}


When I run the program through windows command prompt it just prints "Hello World" and the program ends, with no error messages, not waitting for me to input the integer. I don't know what I do wrong. Is there any trick I don't know?










share|improve this question














I made a simple program on java:



public class HelloWorld {

public static void main(Stringargs) {
System.out.print(" Hello World");
int n=Integer.parseInt(args[0]);
StdOut.println();
StdOut.print(n);
}
}


When I run the program through windows command prompt it just prints "Hello World" and the program ends, with no error messages, not waitting for me to input the integer. I don't know what I do wrong. Is there any trick I don't know?







windows command-line java prompt helpfile






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 19:49







GEOMAZ











migrated from superuser.com Jan 18 at 22:10


This question came from our site for computer enthusiasts and power users.









migrated from superuser.com Jan 18 at 22:10


This question came from our site for computer enthusiasts and power users.










  • 2





    Try to understand what each line does.

    – gronostaj
    Jan 18 at 19:51






  • 1





    Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

    – slhck
    Jan 18 at 19:57














  • 2





    Try to understand what each line does.

    – gronostaj
    Jan 18 at 19:51






  • 1





    Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

    – slhck
    Jan 18 at 19:57








2




2





Try to understand what each line does.

– gronostaj
Jan 18 at 19:51





Try to understand what each line does.

– gronostaj
Jan 18 at 19:51




1




1





Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

– slhck
Jan 18 at 19:57





Why are you expecting the program to wait for you? What line of code do you think would achieve that? Please note that programming questions are off topic here.

– slhck
Jan 18 at 19:57












1 Answer
1






active

oldest

votes


















0














Think of why you are passing a string array, called args, into your program. Perhaps for something like arguments?



That is an array of arguments passed into your program as strings, which is whatever follows in on the command. If the zeroth argument does not work, then try the first (args[1])



Try this



java hello 23



This passes 23 into the program as a string. Integer.parseInt(args[0]) parses it as an integer, and then the other lines display it. Try this and come back if it still fails.



On another note - this is fairly basic and many would expect you read each line and understand what it does before coding and running it. It's tempting to copy from StackOverflow and forget about it, but its not a good way to learn. One day you will end up running sudo rm -rf / without thinking twice ;)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54262076%2fi-dont-know-how-to-input-through-windows-command-prompt%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Think of why you are passing a string array, called args, into your program. Perhaps for something like arguments?



    That is an array of arguments passed into your program as strings, which is whatever follows in on the command. If the zeroth argument does not work, then try the first (args[1])



    Try this



    java hello 23



    This passes 23 into the program as a string. Integer.parseInt(args[0]) parses it as an integer, and then the other lines display it. Try this and come back if it still fails.



    On another note - this is fairly basic and many would expect you read each line and understand what it does before coding and running it. It's tempting to copy from StackOverflow and forget about it, but its not a good way to learn. One day you will end up running sudo rm -rf / without thinking twice ;)






    share|improve this answer




























      0














      Think of why you are passing a string array, called args, into your program. Perhaps for something like arguments?



      That is an array of arguments passed into your program as strings, which is whatever follows in on the command. If the zeroth argument does not work, then try the first (args[1])



      Try this



      java hello 23



      This passes 23 into the program as a string. Integer.parseInt(args[0]) parses it as an integer, and then the other lines display it. Try this and come back if it still fails.



      On another note - this is fairly basic and many would expect you read each line and understand what it does before coding and running it. It's tempting to copy from StackOverflow and forget about it, but its not a good way to learn. One day you will end up running sudo rm -rf / without thinking twice ;)






      share|improve this answer


























        0












        0








        0







        Think of why you are passing a string array, called args, into your program. Perhaps for something like arguments?



        That is an array of arguments passed into your program as strings, which is whatever follows in on the command. If the zeroth argument does not work, then try the first (args[1])



        Try this



        java hello 23



        This passes 23 into the program as a string. Integer.parseInt(args[0]) parses it as an integer, and then the other lines display it. Try this and come back if it still fails.



        On another note - this is fairly basic and many would expect you read each line and understand what it does before coding and running it. It's tempting to copy from StackOverflow and forget about it, but its not a good way to learn. One day you will end up running sudo rm -rf / without thinking twice ;)






        share|improve this answer













        Think of why you are passing a string array, called args, into your program. Perhaps for something like arguments?



        That is an array of arguments passed into your program as strings, which is whatever follows in on the command. If the zeroth argument does not work, then try the first (args[1])



        Try this



        java hello 23



        This passes 23 into the program as a string. Integer.parseInt(args[0]) parses it as an integer, and then the other lines display it. Try this and come back if it still fails.



        On another note - this is fairly basic and many would expect you read each line and understand what it does before coding and running it. It's tempting to copy from StackOverflow and forget about it, but its not a good way to learn. One day you will end up running sudo rm -rf / without thinking twice ;)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 18 at 21:23









        QuickishFMQuickishFM

        1114




        1114
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54262076%2fi-dont-know-how-to-input-through-windows-command-prompt%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            Puebla de Zaragoza

            Musa