1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Rep Power

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

    -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:
    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") )
    			// 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
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Eastern Florida
    Rep Power
    What problems are you having with the program? What does it do now?

    Also posted at http://www.javaprogrammingforums.com/whats-wrong-my-code/32252-how-search-upper-lower-case-using-string-using-java.html
    Last edited by NormR; September 25th, 2013 at 06:56 AM.

IMN logo majestic logo threadwatch logo seochat tools logo