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;
}
}
java command-line command-line-arguments
add a comment |
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;
}
}
java command-line command-line-arguments
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 theargs
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
add a comment |
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;
}
}
java command-line command-line-arguments
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
java command-line command-line-arguments
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 theargs
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
add a comment |
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 theargs
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
add a comment |
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;
}
}
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
add a comment |
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;
}
}
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
add a comment |
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;
}
}
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
add a comment |
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;
}
}
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;
}
}
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
add a comment |
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
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.
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.
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%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
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
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