Need to pass this code as a command line argument but I'm not sure how. This works in Eclipse but not cmd











up vote
0
down vote

favorite












The code works in Eclipse but not command so I did it wrong. I have to pass this as an argument from command line?



public class Unit05_Prog1 {

public static void main(String args) {
// Prompt the user to enter a string
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();

int count = count(s);
System.out.println("Number of Lower Case Character is : " +count);
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}









share|improve this question
























  • Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
    – chrylis
    Nov 10 at 0:56






  • 1




    Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
    – dave
    Nov 10 at 0:57










  • Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
    – Stephen C
    Nov 10 at 1:04












  • id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
    – qahopeful
    Nov 11 at 3:19










  • HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:22















up vote
0
down vote

favorite












The code works in Eclipse but not command so I did it wrong. I have to pass this as an argument from command line?



public class Unit05_Prog1 {

public static void main(String args) {
// Prompt the user to enter a string
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();

int count = count(s);
System.out.println("Number of Lower Case Character is : " +count);
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}









share|improve this question
























  • Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
    – chrylis
    Nov 10 at 0:56






  • 1




    Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
    – dave
    Nov 10 at 0:57










  • Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
    – Stephen C
    Nov 10 at 1:04












  • id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
    – qahopeful
    Nov 11 at 3:19










  • HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:22













up vote
0
down vote

favorite









up vote
0
down vote

favorite











The code works in Eclipse but not command so I did it wrong. I have to pass this as an argument from command line?



public class Unit05_Prog1 {

public static void main(String args) {
// Prompt the user to enter a string
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();

int count = count(s);
System.out.println("Number of Lower Case Character is : " +count);
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}









share|improve this question















The code works in Eclipse but not command so I did it wrong. I have to pass this as an argument from command line?



public class Unit05_Prog1 {

public static void main(String args) {
// Prompt the user to enter a string
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();

int count = count(s);
System.out.println("Number of Lower Case Character is : " +count);
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}






java command-line command-line-arguments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 4:06









Andrew Thompson

152k27162336




152k27162336










asked Nov 10 at 0:53









qahopeful

1




1












  • Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
    – chrylis
    Nov 10 at 0:56






  • 1




    Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
    – dave
    Nov 10 at 0:57










  • Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
    – Stephen C
    Nov 10 at 1:04












  • id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
    – qahopeful
    Nov 11 at 3:19










  • HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:22


















  • Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
    – chrylis
    Nov 10 at 0:56






  • 1




    Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
    – dave
    Nov 10 at 0:57










  • Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
    – Stephen C
    Nov 10 at 1:04












  • id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
    – qahopeful
    Nov 11 at 3:19










  • HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:22
















Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
– chrylis
Nov 10 at 0:56




Describe exactly what "working" means, along with "this". Also, you don't seem to be actually using anything from the command line, just console input.
– chrylis
Nov 10 at 0:56




1




1




Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
– dave
Nov 10 at 0:57




Your command line arguments are delivered to your program via the args parameter. None of your code accesses this variable, so I'm puzzled why you think there's different behaviour between your IDE and the command line.
– dave
Nov 10 at 0:57












Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
– Stephen C
Nov 10 at 1:04






Your program works for me from the command line without any modification or any special tricks. Please explain in more detail what your problem is. And what do you mean by passing code as a command line argument?
– Stephen C
Nov 10 at 1:04














id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
– qahopeful
Nov 11 at 3:19




id like to be able to use command line. when i run this in eclipse i can enter a string of letters and it tells me how many are lowercase. it wont work using cmd
– qahopeful
Nov 11 at 3:19












HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
– qahopeful
Nov 11 at 3:22




HERE IS WHAT IM TRYING TO DO For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
– qahopeful
Nov 11 at 3:22












1 Answer
1






active

oldest

votes

















up vote
0
down vote













if you want to get input as an argument just change :



public class Unit05_Prog1 {

public static void main(String args) {
if(args.length > 0){
int count = count(args[0]);
System.out.println("Number of Lower Case Character is : " +count);
}
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}





share|improve this answer





















  • this returns nothing when i run it
    – qahopeful
    Nov 11 at 3:19










  • For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:21








  • 1




    ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
    – qahopeful
    Nov 12 at 2:29











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',
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%2f53235071%2fneed-to-pass-this-code-as-a-command-line-argument-but-im-not-sure-how-this-wor%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








up vote
0
down vote













if you want to get input as an argument just change :



public class Unit05_Prog1 {

public static void main(String args) {
if(args.length > 0){
int count = count(args[0]);
System.out.println("Number of Lower Case Character is : " +count);
}
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}





share|improve this answer





















  • this returns nothing when i run it
    – qahopeful
    Nov 11 at 3:19










  • For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:21








  • 1




    ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
    – qahopeful
    Nov 12 at 2:29















up vote
0
down vote













if you want to get input as an argument just change :



public class Unit05_Prog1 {

public static void main(String args) {
if(args.length > 0){
int count = count(args[0]);
System.out.println("Number of Lower Case Character is : " +count);
}
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}





share|improve this answer





















  • this returns nothing when i run it
    – qahopeful
    Nov 11 at 3:19










  • For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:21








  • 1




    ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
    – qahopeful
    Nov 12 at 2:29













up vote
0
down vote










up vote
0
down vote









if you want to get input as an argument just change :



public class Unit05_Prog1 {

public static void main(String args) {
if(args.length > 0){
int count = count(args[0]);
System.out.println("Number of Lower Case Character is : " +count);
}
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}





share|improve this answer












if you want to get input as an argument just change :



public class Unit05_Prog1 {

public static void main(String args) {
if(args.length > 0){
int count = count(args[0]);
System.out.println("Number of Lower Case Character is : " +count);
}
}

public static int count(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if(Character.isLowerCase(str.charAt(i))) //check for lower case character
count++;
}
return count;
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 4:21









saeedata

38616




38616












  • this returns nothing when i run it
    – qahopeful
    Nov 11 at 3:19










  • For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:21








  • 1




    ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
    – qahopeful
    Nov 12 at 2:29


















  • this returns nothing when i run it
    – qahopeful
    Nov 11 at 3:19










  • For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
    – qahopeful
    Nov 11 at 3:21








  • 1




    ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
    – qahopeful
    Nov 12 at 2:29
















this returns nothing when i run it
– qahopeful
Nov 11 at 3:19




this returns nothing when i run it
– qahopeful
Nov 11 at 3:19












For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
– qahopeful
Nov 11 at 3:21






For this part create a program named Unit05_Prog1.java that will accept one argument from the command line, which will be a string (you can't get anything else, right?). The program will then check each character in that string and determine if it is a lowercase character or not and keep a count. When it hits the end of the String it will print out how many lowercase characters there are.
– qahopeful
Nov 11 at 3:21






1




1




ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
– qahopeful
Nov 12 at 2:29




ok i got it now. i was doing this wrong. i was running the java file and not entering anything after the file name in command line. found a youtube vid that saved me. thanks so much!!!
– qahopeful
Nov 12 at 2:29


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53235071%2fneed-to-pass-this-code-as-a-command-line-argument-but-im-not-sure-how-this-wor%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

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff