1 Reply Latest reply: Sep 25, 2013 2:55 AM by PhHein RSS

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

    978623

      -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]