473,387 Members | 1,834 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.

Counting how many letters and numbers

I'm trying to count how many letters and how many numbers are in a user input string. For example:
Number01: should display
2 numbers
6 letters

So far, I've counted how many letters there are but I don't know how to add numbers to the string.

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.JOptionPane;
  2.  
  3. public class morePractice {
  4.  
  5.     public static void main(String[] args) {
  6.         String str;
  7.         int num1;
  8.         int total=0;
  9.         char letter;
  10.         int totalNum=0;
  11.  
  12.         str=JOptionPane.showInputDialog(null,"Enter phrase");
  13.  
  14.         for(int i=0;i<str.length();i++){
  15.             letter=str.charAt(i);
  16.             if(letter>='A'&&letter<='Z' || letter>='a'&&letter<='z'){
  17.                 total++;
  18.             }
  19.  
  20.         }
  21.         JOptionPane.showMessageDialog(null,"There are " + total + " letters");
  22.  
  23.     }
  24.  
  25. }
  26.  
Mar 5 '13 #1

✓ answered by Rabbit

Do the same thing, except for the characters '0' to '9'

1 1271
Rabbit
12,516 Expert Mod 8TB
Do the same thing, except for the characters '0' to '9'
Mar 5 '13 #2

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

Similar topics

4
by: Sugapablo | last post by:
Does anyone have a handy-dandy function they can quickly post that strips everything from a string except for letters, numbers, & underscores? -- http://www.sugapablo.com <--music ]...
8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
6
by: carl.barrett | last post by:
Hi, I have a table that Stores individual records about a person and the dates that a number of letters were sent to them, e.g. Date First Letter Sent: 01/04/05 Date Second Letter Sent:...
1
by: Jon Gunnar Rue | last post by:
I have a textbox accepting both numbers and letters. Is there a way to convert this over to a hex string so I may use it in another textbox ? --- Jon Gunnar Rue ICQ: 15839694 MSN:...
1
by: c_323_h | last post by:
Hi, I need this fast 10pm today. I need help with some code. I am working on this program...a user inputs an integer (For example, 50) between 1 and 100. I have a for loop that generates random...
1
by: Kosmos | last post by:
Since people have been so helpful on this site I thought I'd contribute what little I can...since I am not a programmer but I'm working on an access database for work Anyways I had to remove...
9
by: Chelong | last post by:
Hi All I am using the srand function generate random numbers.Here is the problem. for example: #include<iostream> #include <time.h> int main() {
1
by: jpalhinhas | last post by:
hi guys, i've seen this effect in a signature of an email and can't do it myself now. i remember it was html code cause I saw the source but deleted the email by mistake. so, once the mouse was...
3
by: Piotr Sobolewski | last post by:
Hello, I have three tables: persons, telephone_numbers and email_addresses. They are connected one-to-many: - one person has many telephone numbers, - one person has many email addresses. I...
2
by: lmao29 | last post by:
hi guys, i am new to JAVA I am having trouble with array, anyone can help? here is the problem. if i input 10 numbers, how can i count the unique numbers and output them here is the example: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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.