473,387 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do i put together JOptionPane and letter counter to work?

I took a look at the site and found this as a counter. Is there any way I can use it in a dialog box, that asks user to input any number of letters in a (?)dialog box, pressing enter and out comes Number of upper/lower case e's in the (I)dialog box. Also have it repeat process until user enters Stop. Well yeah, thanks if anyone can help put that up tonight..



String str = "Count" ;

char ch = 'e';
char ch2 = 'E';

int count = 0 ;
int counter = 0;
int pos = -1 ;

while( ( pos = str.indexOf( ch, pos + 1 ) ) > -1 ) count++ ;

System.out.println( "Number of lower case e's: + count + " ) ;

while( ( pos = str.indexOf( ch2, pos + 1 ) ) > -1 ) counter++ ;

System.out.println( "Number of upper case e's + counter + " ) ;
Sep 10 '07 #1
2 2020
r035198x
13,262 8TB
I took a look at the site and found this as a counter. Is there any way I can use it in a dialog box, that asks user to input any number of letters in a (?)dialog box, pressing enter and out comes Number of upper/lower case e's in the (I)dialog box. Also have it repeat process until user enters Stop. Well yeah, thanks if anyone can help put that up tonight..



String str = "Count" ;

char ch = 'e';
char ch2 = 'E';

int count = 0 ;
int counter = 0;
int pos = -1 ;

while( ( pos = str.indexOf( ch, pos + 1 ) ) > -1 ) count++ ;

System.out.println( "Number of lower case e's: + count + " ) ;

while( ( pos = str.indexOf( ch2, pos + 1 ) ) > -1 ) counter++ ;

System.out.println( "Number of upper case e's + counter + " ) ;
1.) Use code tags when posting code.
2.) Where are you checking for upper case and lower case? Check out the Character class for the relevant methods.
Sep 10 '07 #2
Nepomuk
3,112 Expert 2GB
I took a look at the site and found this as a counter. Is there any way I can use it in a dialog box, that asks user to input any number of letters in a (?)dialog box, pressing enter and out comes Number of upper/lower case e's in the (I)dialog box. Also have it repeat process until user enters Stop. Well yeah, thanks if anyone can help put that up tonight..



String str = "Count" ;

char ch = 'e';
char ch2 = 'E';

int count = 0 ;
int counter = 0;
int pos = -1 ;

while( ( pos = str.indexOf( ch, pos + 1 ) ) > -1 ) count++ ;

System.out.println( "Number of lower case e's: + count + " ) ;

while( ( pos = str.indexOf( ch2, pos + 1 ) ) > -1 ) counter++ ;

System.out.println( "Number of upper case e's + counter + " ) ;
That is one possibility to go through it, but it'll be a lot of unnecessary coding. As r035198x said, check the Character class. Also, I'd just go through the String once and in that loop check if the given Character is upper or lower case. You're code would look something like this:
Expand|Select|Wrap|Line Numbers
  1. String str = "Count";
  2. int lower = 0;
  3. int upper = 0;
  4. while(int i=0; i<str.length(); i++)
  5. {
  6.    if (...)      // Check, if str.charAt(i) is lower case
  7.       lower++;
  8.    else if (...) // Check, if str.charAt(i) is upper case
  9.       upper++;
  10. }
  11.  
Greetings,
Nepomuk
Sep 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: - Steve - | last post by:
Example String testString = "Testing \t tabs"; JOptionPane.showMessageDialog(null, testString, "TEST", JOptionPane.INFORMATION_MESSAGE); Instead of getting the output "Testing tabs", I...
1
by: jazzy | last post by:
Hi, I am new to Java Programming and I am trying to write code using JOption pane to prompt user to type information and then have string output command to display information on the screen. I...
2
by: jek339 | last post by:
Hey, I'm totally new to Java, and I'm taking a class. My current assignment involves inputting 2 names and corresponding bdays for each name using the JOptionPane.showInputDialog etc. Anyway, I'm...
2
by: gdarian216 | last post by:
the program reads input from a file and then outputs the averages and grade. for some reason it is reading in the same line twice and it doesn't print out the grade. everything else is correct, if...
3
by: majorecono | last post by:
What I'm bad at is the dialog box part. This is the code Ive come up with... if you see a way to improve what im thinkng of.... post it please. Program should.... 1. Ask user to type in a...
1
by: Smarteric | last post by:
import javax.swing.JOptionPane; public class MilesPerGallon { public static void main(String args) { String miles; String gallons; double MPG; double miles1, gallons1;
5
by: Ramola | last post by:
hi, I was wondering if i can customise a JOptionPane ??? ex : A JOptionPane by default has a background color gray............. can i change it ?? can i put some images in the background ? Its...
3
by: heat84 | last post by:
I want to customise JOptionPane and add a KeyListener to it. I want to behave in a certain manner when the enter key is pressed , but from the look of things, the key listener I am adding to the...
13
by: umpsumps | last post by:
Hello, Here is my code for a letter frequency counter. It seems bloated to me and any suggestions of what would be a better way (keep in my mind I'm a beginner) would be greatly appreciated.. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.