Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

passing a string to main mehtod

wiredwirede2m
wiredwirede2m 


I need to finish writing code in java. The problem is: write a program that passes a string to the main method and displays the number of uppercase letters in the string. The program has to be able to use the command prompt. This is what i started, but it doesnt work in the command line: public class NineOneSix { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Prompt the user to enter a string System.out.print("Enter a string: "); String s = input.nextLine(); String upper =""; for (int i = 0; i < s.length(); i++) { char thisChar = s.charAt(i); if (thisChar >= 60 && thisChar <= 90) { upper += thisChar; // close scanner input.close(); } } System.out.println("Upper case letters: " + upper.length() + " = " + upper); } } Attachments
Tags Clarifications

Answers

JAVA pass to main solution

Seeker
Seeker 



To run from command line:

java NineOneSix YourStringHere

To run from Eclipse:

Click on the run menu at the top and go into run configuration. Click on the arguments tab and enter your string into the program arguments text box.
Attachments
NineOneSix.java (1 K) Download Preview
<= 0){ System.out.println("No arguments were entered in the command line. Please Retry"); System.exit(0); } String argument = args[0].toString(); String upper ="";

Screenshots
Purchase Answer