Sign in with
Sign up | Sign in
Your question

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

Last response: in Apps General Discussion
Share
September 24, 2013 4:23:32 PM

-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".

  1. "
  2. public class Project0 {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. String[] uppercase = {'E'};
  7. String[] lowercase = {'e'};
  8. String isOrIsNot, inputWord;
  9.  
  10. while (true) {
  11. // This line asks the user for input by popping out a single window
  12. // with text input
  13. inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
  14.  
  15. if ( inputWord.equals("stop") )
  16. System.exit(0);
  17.  
  18. // if the inputWord is contained within uppercase or
  19. // lowercase return true
  20. if (wordIsThere(inputWord, lowercase))
  21. isOrIsNot = "Number of lower case e's: ";
  22.  
  23. if (wordIsThere(inputword, uppercase))
  24. isOrIsNot = "number of upper case e's: ";
  25.  
  26. // Output to a JOptionPane window whether the word is on the list or not
  27. JOptionPane.showMessageDialog(null, "The word " + inputWord + " " + isOrIsNot + " on the list.");
  28. }
  29. } //main
  30.  
  31. public static boolean wordIsThere(String findMe, String[] theList) {
  32. for (int i=0; i<theList.length; ++i) {
  33. if (findMe.equals(theList[i])) return true;
  34. }
  35.  
  36. return false;
  37. } // wordIsThere
  38. } // class Lab4Program1
  39.  
  40. "
September 24, 2013 5:56:18 PM

sound like you need to talk to your TA/teacher/professor.
m
0
l
!