473,406 Members | 2,710 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,406 software developers and data experts.

Help, I am having problems with loops.

I need help with a program I am writing for school. The program has to do the following:
/*
1. Character string must be a minimium of 15 charactors.

2. If not 15 characters long it must give error and send you back to orginal question.

3. After entering 15 characters it must count the CAPTIAL letters and tell you how many there are.

4. Need a loop to count and produce error and take you back to first screen.
*/

My code is below. It does almost ever thing I need it to. EXCEPT a loop after you NOT entering aleast 15 characters. I know it something simple and I am confussed on Nested Loops. I have been reading and reading for days. I have almost 30 hours into this, (that is including all the reading). I know this is simple, it is just the light bulb has not come on in my head yet. Can some one help me with the part I am missing. If you enter the correct amount of characters it works. The loop for the error is not working correctly.

Please help!!!!

import javax.swing.*;
import java.text.*;

public class Characters1
{
public static void main (String [] args)
{
int count = 0;
char c1 = 0;
String response = null;
boolean b1 = Character.isUpperCase(c1);

while(true)
{
response = JOptionPane.showInputDialog (null,
"Please Enter a sting of characters that is at least 15 characters long.");
{
if (response.length() < 15)
{
JOptionPane.showMessageDialog (null,"You did enter enought characters");
{
response = JOptionPane.showInputDialog (null,"Please Enter a sting of characters that is at least 15 characters long.");
}
}
int length = response.length();


{
if (length > 15)

for (int i=0; i<length; i++)
if (Character.isUpperCase(response.charAt(i)))
count++;


JOptionPane.showMessageDialog (null, "You entered "+length+" characters "+count+ " of them were captial letters");

System.exit(0); //Must use with JOptionPane

}
}
}}
}



Thanks for your help,
S Black
Nov 20 '06 #1
2 1812
r035198x
13,262 8TB
I need help with a program I am writing for school. The program has to do the following:
/*
1. Character string must be a minimium of 15 charactors.

2. If not 15 characters long it must give error and send you back to orginal question.

3. After entering 15 characters it must count the CAPTIAL letters and tell you how many there are.

4. Need a loop to count and produce error and take you back to first screen.
*/

My code is below. It does almost ever thing I need it to. EXCEPT a loop after you NOT entering aleast 15 characters. I know it something simple and I am confussed on Nested Loops. I have been reading and reading for days. I have almost 30 hours into this, (that is including all the reading). I know this is simple, it is just the light bulb has not come on in my head yet. Can some one help me with the part I am missing. If you enter the correct amount of characters it works. The loop for the error is not working correctly.

Please help!!!!

import javax.swing.*;
import java.text.*;

public class Characters1
{
public static void main (String [] args)
{
int count = 0;
char c1 = 0;
String response = null;
boolean b1 = Character.isUpperCase(c1);

while(true)
{
response = JOptionPane.showInputDialog (null,
"Please Enter a sting of characters that is at least 15 characters long.");
{
if (response.length() < 15)
{
JOptionPane.showMessageDialog (null,"You did enter enought characters");
{
response = JOptionPane.showInputDialog (null,"Please Enter a sting of characters that is at least 15 characters long.");
}
}
int length = response.length();


{
if (length > 15)

for (int i=0; i<length; i++)
if (Character.isUpperCase(response.charAt(i)))
count++;


JOptionPane.showMessageDialog (null, "You entered "+length+" characters "+count+ " of them were captial letters");

System.exit(0); //Must use with JOptionPane

}
}
}}
}



Thanks for your help,
S Black
Always a pleasure to help those that write their own code first.

Expand|Select|Wrap|Line Numbers
  1.  import javax.swing.*;
  2. import java.text.*; 
  3. public class Characters1 {
  4.  public static void main (String [] args) {
  5.   int count = 0;
  6.   char c1 = 0;
  7.   String response = null;
  8.   boolean correct = false;
  9.   while(!correct) {
  10.    response = JOptionPane.showInputDialog (null,
  11.    "Please Enter a sting of characters that is at least 15 characters long.");
  12.    if (response.length() < 15) {
  13.     JOptionPane.showMessageDialog (null,"You did not enter enough characters");
  14.    }
  15.    else {
  16.     correct = true;
  17.    }
  18.   }
  19.  
  20.   for (int i=0; i<response.length(); i++) {
  21.    if (Character.isUpperCase(response.charAt(i))) {
  22.     count++;
  23.    }
  24.   }
  25.   JOptionPane.showMessageDialog (null, "You entered "+response.length()+" characters "+count+ " of them were captial letters");
  26.   System.exit(0); //Must use with JOptionPane
  27.  }
  28. }
  29.  
  30.  
Nov 20 '06 #2
Thanks so much for you help, I really needed it. I am going nuts with this.
Nov 21 '06 #3

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

Similar topics

37
by: Tim Marshall | last post by:
From http://www.mvps.org/access/tencommandments.htm 9th item: Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you...
6
by: fool | last post by:
Dear group, Given a string I have to print the permutation, using some looping tricks. This is not a Home work problem. My best try as beginner is: #include<stdio.h> #include<stdlib.h> ...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
5
Reika
by: Reika | last post by:
Hello, I need help understanding some things in programming. I'm taking a high school level programming course, however my teacher is less than helpful in explaining or even understanding the...
2
by: Toby | last post by:
I'm trying to write a simple commandline wrapper: a script that runs another program as a child and relays unbuffered stdin and stdout to/from the child process, possibly filtering it. The...
1
by: tkempy | last post by:
okay so i have a CIS class called abstraction and design. i'm completely new to this "java" stuff. I've never seen any of it in my life. our second homework is to create a program that produces a...
1
by: jiggaman828 | last post by:
Am I doing something wrong with setting my width? I thought I had it correct. Can any inform me on how to write 4 different while or do-while loops counting down to 0, it has to be lined up column...
8
by: Dameon99 | last post by:
my program compiles without problems but when i try to run it pauses shortly and then crashes. When i set it to debug it came up with the following message: "An Access Violation (Segmentation...
2
by: djcamo | last post by:
Hi, I'm hoping some one can help with some coding issues I'm having. Below is some code I use to rename a file if it already exists in a folder. As you can see I have 5 nested if loops which means...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.