The Artima Developer Community
Sponsored Link

Java Answers Forum
error loop boolean

1 reply on 1 page. Most recent reply: Nov 29, 2005 11:43 PM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
patricia feaster

Posts: 1
Nickname: blinktrish
Registered: Nov, 2005

error loop boolean Posted: Nov 29, 2005 5:04 PM
Reply to this message Reply
Advertisement
Howdy - am in the process of creating a program where a user enters the number of people in their family. The loop is suppose to loop the number of member in their family.. I got it to loop but it gives me a error stating that the int needs to be a boolean.. i am not really sure what it asking me.

for(int count = 1; count < familyMembers; count--)
System.out.println("enter member one's first name, last name, age, weight, height.");

firstName1 = keyboard.next();
lastName1 = keyboard.next();
age1 = keyboard.nextInt();
weight1 = keyboard.nextInt();
height1 = keyboard.nextInt();

if(count = 2)
System.out.println("enter member two's first name, last name, age, weight, height.");

firstName2 = keyboard.next();
lastName2 = keyboard.next();
age2 = keyboard.nextInt();
weight2 = keyboard.nextInt();
height2 = keyboard.nextInt();

I did that all the way to six.. we have not covered arrays so I do not think i can work ahead.

the whole program is to take all family info and avgerage out the age, weight, height; tell who is the oldest, tallest, & fatest.
I could send what I have thus far.. i think its about 1/2 done, but its due by friday. thank you much for your time and I look forward to hearing from you.

VR

P.feaster


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: error loop boolean Posted: Nov 29, 2005 11:43 PM
Reply to this message Reply
1. Format your code using the java tags as shown in the "Formatting your post" section

2. To your problem:

The result of 'count = 2' is integer, not boolean. This way you assign a value.
The correct syntax would be 'if (count == 2)'

3. Endless loop
'for(int count = 1; count < familyMembers; count--)'
As long as familyMembers is not <= 0 this loop will run for a very long time.
You need an increment, not a decremnt
'for(int count = 1; count < familyMembers; count++)'

Flat View: This topic has 1 reply on 1 page
Topic: JPG Previous Topic   http://localhost:8080">Next Topic http://localhost:8080">Topic: java.io.FileNotFoundException: <a href=http://localhost:8080" border="0">

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use