AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

newbie help needed with looping.

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Trevnal
Guest





PostPosted: Sun Apr 24, 2005 6:57 pm    Post subject: newbie help needed with looping. Reply with quote



Hi,
I was hoping some one may be able to help me. I am trying to get a piece of
code to work, which I thought I had right. But as far as I can tell, it does
not do anything when I run it in jBuilder.
I want to make sure the string that is collected from Keyboard.getString is
a upper case letter and the total length of the string is 8 characters long.

int len;
boalean validName = true;

aa = Keyboard.getString();
while (!aa.equals("ZZZ"))
{
do
{
len = partNumber.length();
{
if (!len == Cool
{
validName = false
}
}
}
while (validName = false)

do
{
for (int index = 0; index <2; index ++)
{
if (aa.substring(index,index+1) <"A" \
(aa.substring(index,index+1) >"Z")
{
validName = false;
}
}
}
while (validName = false)

do
{
for (int index = 1; index <3; index ++)
{
if (aa.substring(index,index+1) <"0" \
(aa.substring(index,index+1) >"100")
{
validName = false;
}
}
}
while (validName = false)

partIn[index] = new Part();
partIn[index].setPartNumber(partNumber);
}

rest of code.

thanks
Hobbit



Back to top
googmeister@gmail.com
Guest





PostPosted: Sun Apr 24, 2005 8:15 pm    Post subject: Re: newbie help needed with looping. Reply with quote



Quote:
while (validName = false)

= vs. ==


Back to top
Tor Iver Wilhelmsen
Guest





PostPosted: Sun Apr 24, 2005 10:13 pm    Post subject: Re: newbie help needed with looping. Reply with quote



"Trevnal" <trevnal (AT) lacy (DOT) seriouslyinternet.com> writes:

Quote:
do
{
len = partNumber.length();
{
if (!len == Cool
{
validName = false
}
}
}
while (validName = false)

Apart from the = vs. == thingy, you never actually assign to
partNumber here, so either the loop exits at the first run, or it
enters an endless loop.

Quote:
if (aa.substring(index,index+1) <"A" \
(aa.substring(index,index+1) >"Z")

You cannot use < and > operators on strings. Use compareTo. Or use
charAt() instead of substring(), then you can compare to 'A' and 'Z'
using < and >.

Quote:
if (aa.substring(index,index+1) <"0" \
(aa.substring(index,index+1) >"100")

What does that mean?

Back to top
.
Guest





PostPosted: Wed Apr 27, 2005 8:52 pm    Post subject: Re: newbie help needed with looping. Reply with quote

On Sun, 24 Apr 2005, Trevnal wrote:

Quote:
Hi,
I was hoping some one may be able to help me. I am trying to get a piece of
code to work, which I thought I had right. But as far as I can tell, it does
not do anything when I run it in jBuilder.
I want to make sure the string that is collected from Keyboard.getString is
a upper case letter and the total length of the string is 8 characters long.

int len;
boalean validName = true;

I assume you typed this in by hand rather that copying and pasting the
code. boalean should be boolean.

Quote:
aa = Keyboard.getString();

I think it is safe to assume that getString() is a static method in the
class Keyboard and it returns a String.

Quote:
while (!aa.equals("ZZZ")) {

If the user enters "ZZZ" then we quit.

Quote:
do {
len = partNumber.length();

I would assume that partNumber.length() returns the length of some string.
I would not assume it would change the length of partNumber. This is
important. See below.

Quote:
{

Why the extra scope here? This seems pointless to me.

Quote:
if (!len == Cool {
validName = false
}

If the length of partNumber is not 8 then validName is false. If the
length never changes (i.e. partNumber.length() does not change the length)
then this will either exit immediately or loop forever.

Quote:
}
} while (validName = false)

Two problems. The = is for assignment. The == is for comparison. Second
problem, you need a semicolon at the end of the line.

Did you put some println() statements in the code to see if it got this
far? Just putting things like:

System.out.println("just before the IF");
and
System.out.println("at the bottom of the loop");

will help you see how things are running. If it prints out, over and over
then you know you have an endless loop.

Once you get this part of the code working, if you still have problems,
post the rest.

Quote:
do {
for (int index = 0; index <2; index ++) {
if (aa.substring(index,index+1) <"A" \
(aa.substring(index,index+1) >"Z") {
validName = false;
}
}
} while (validName = false)

do {
for (int index = 1; index <3; index ++) {
if (aa.substring(index,index+1) <"0" \
(aa.substring(index,index+1) >"100") {
validName = false;
}
}
} while (validName = false)

partIn[index] = new Part();
partIn[index].setPartNumber(partNumber);
}

rest of code.

thanks
Hobbit





--
Send e-mail to: darrell dot grainger at utoronto dot ca


Back to top
Harald
Guest





PostPosted: Sun May 01, 2005 4:32 pm    Post subject: Re: newbie help needed with looping. Reply with quote

"Trevnal" <trevnal (AT) lacy (DOT) seriouslyinternet.com> writes:

Well, since you call yourself a newbie I dare to point you to

http://java.sun.com/docs/codeconv/html/CodeConventions.doc6.html#460

concerning your placement of braces in the code. The rest of the
document is also quite useful.

Harald.
P.S.: The group comp.lang.java does not exist (anymore).

--
---------------------+---------------------------------------------
Harald Kirsch (@home)|
Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.