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 + " ) ;
2 2020
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.
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: -
String str = "Count";
-
int lower = 0;
-
int upper = 0;
-
while(int i=0; i<str.length(); i++)
-
{
-
if (...) // Check, if str.charAt(i) is lower case
-
lower++;
-
else if (...) // Check, if str.charAt(i) is upper case
-
upper++;
-
}
-
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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;
|
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...
|
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...
|
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..
...
|
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,...
|
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$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
| |