Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to search for upper/lower case using string using JAVA!!!?

978623Sep 24 2013 — edited Sep 25 2013

-I am trying to write a program that will examine each letter in the string and count how many time the upper-case letter 'E' appears, and how many times the lower-case letter 'e' appears.

-I also have to use a JOptionPane.showMessageDialog() to tell the user how many upper and lower case e's were in the string.

-This will be repeated until the user types the word "Stop". 

please help if you can

what i have so far:

[code]

public class Project0 {

public static void main(String[] args) {

  String[] uppercase = {'E'};
  String[] lowercase = {'e'};
  String isOrIsNot, inputWord;
  
  while (true) {
   // This line asks the user for input by popping out a single window
   // with text input
   inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
  
   if ( inputWord.equals("stop") )
    System.exit(0);
  
   // if the inputWord is contained within uppercase or
   // lowercase return true
   if (wordIsThere(inputWord, lowercase))
    isOrIsNot = "Number of lower case e's: ";

   if (wordIsThere(inputword, uppercase))
     isOrIsNot = "number of upper case e's: ";
  
   // Output to a JOptionPane window whether the word is on the list or not
   JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
  }
} //main

public static boolean wordIsThere(String findMe, String[] theList) {
  for (int i=0; i<theList.length; ++i) {
   if (findMe.equals(theList[i])) return true;
  }
 
  return false;
} // wordIsThere
} // class Lab4Program1

[/code]

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2013
Added on Sep 24 2013
1 comment
615 views