0

I need to write a program that takes in an input using JOptionPane and make sure it is more than 15 characters, then count the number of uppercases in the phrase. Please help desperate student.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by imclumsy
0

Hey...this works for a string...maybe you can modify it to what you are wanting:

int count = 0;
		int UpperCaseCount = 0;
		char[] newCharArray = new char[100];
		do {
			System.out.println("Enter a string: ");
			Scanner sc = new Scanner(System.in);
			String theString = sc.nextLine();			
			for (int i=0; i< theString.length(); i++)
			{
				newCharArray[i] = theString.charAt(i);
				count++;			
			}
			System.out.println(count);
			if (count <15)
			{
				System.out.println("String Rejected.");
				count = 0;
				
			}
		} while(count < 15);
		for (int i=0; i < newCharArray.length; i++) {
			char a = newCharArray[i];
			int charVal = a;
			if (charVal > 60 && charVal < 90) {
				UpperCaseCount++;
			}
				
		}
		System.out.println(UpperCaseCount);

It just does not work if the string has white spaces, but you can figure something like that out...it shouldn't be that hard to take it out...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.