Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 5th, 2007, 09:05 PM
ff4930 ff4930 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 17 ff4930 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 7 m 59 sec
Reputation Power: 0
New to java(have code) need very simple corrections

Hi, thanks for viewing my thread. I have this code 99% but im alittle stuck. The program suppose to read in a sentence and report back how many lower and upper case 'e' it has. But exits when user inputs "Stop" or "stop" and thats where I am stuck here is my code.

Code:
import javax.swing.JOptionPane;

public class firstProject{
	public static void main(String[] args){
	
	
	
	while(true){
	int lowerECount = 0, higherECount = 0;
	
	String sentence = JOptionPane.showInputDialog(null, "Enter a sentence");
		if(sentence == "Stop" || sentence == "stop"){
			System.exit(0);
		}


		
		for(int i = 0; i < sentence.length(); i++){
			if(sentence.charAt(i) == 'e'){
				lowerECount++;
			}
				if(sentence.charAt(i) == 'E'){
				 	higherECount++;
				}
		}//for

		
		JOptionPane.showMessageDialog(null, "number of lower case e's are: " + lowerECount +
						" " + "number of higher case e's are: " + higherECount);


		}//while				 
	



	}//main

}//class

Reply With Quote
  #2  
Old February 6th, 2007, 09:14 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
You might want to consider switching the code around.
I haven't tested this, and it might be wrong, but try playing with this for a bit.

Code:
String sentence = new String("");
while(!sentence.equals("Stop")){
	int lowerECount = 0, higherECount = 0;
	
	sentence = JOptionPane.showInputDialog(null, "Enter a sentence");

//   [ ... ]

}
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > New to java(have code) need very simple corrections


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT