I don't know how to input through windows command prompt
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
migrated from superuser.com Jan 18 at 22:10
This question came from our site for computer enthusiasts and power users.
add a comment |
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
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
add a comment |
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
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
windows command-line java prompt helpfile
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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 ;)
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ;)
add a comment |
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 ;)
add a comment |
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 ;)
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 ;)
answered Jan 18 at 21:23
QuickishFMQuickishFM
1114
1114
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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