LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 311 users online 222973 members 249 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
Dexus
Interests: Music, Movies, Sex, Alcohol, Gaming...
Mood: Sleepy
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
3 online / 20 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

yet again my math skills gets in the way of my java work
Replies: 5Last Post Nov. 10 7:18am by King Kong
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( King Kong )


Ghostbuster

Patron
Reply
got to generate a while loop for this, up to 10.

1, -2, 3, -4, 5,

i think it has something to do with

int1 = 1
int2= -2

while (int2 < 10)
{int1= int1 + 2
int2 = int2 + 2}

but not sure

or should it be

int1 = 1
int2= -2

while (int2 < 10)  
{int1= int1 + 2
int2 = int2 - 2}

Post edited at 6:47 am on Nov. 6, 2009 by King Kong

-------
Pandora didn't think outside the box


6:41 am on Nov. 6, 2009 | Joined: Feb. 2006 | Days Active: 1,094
Join to learn more about King Kong Wales | Straight Male | Posts: 26,390 | Points: 38,429
LiveWire Humor
allsmiles


Enlightened One

Patron
Reply
I'd do something like (not sure if this is exactly how the syntax would work in java or if mod works either...)

Code:
while (int i = 1; i <= 10, i++){
if(i%2){
i++;
i *= -1;
}else{
i*= -1;
i++;
}
}


-------
When they leave me, they're all smiles.
When they leave you, they're in tears.


8:25 am on Nov. 9, 2009 | Joined: Aug. 2007 | Days Active: 575
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 8,896 | Points: 15,976
( King Kong )


Ghostbuster

Patron
Reply
it has to be a while loop.

I know how to do the loop, but my maths sucks

-------
Pandora didn't think outside the box


7:14 am on Nov. 10, 2009 | Joined: Feb. 2006 | Days Active: 1,094
Join to learn more about King Kong Wales | Straight Male | Posts: 26,390 | Points: 38,429
allsmiles


Enlightened One

Patron
Reply
It is a while loop...

-------
When they leave me, they're all smiles.
When they leave you, they're in tears.

7:14 am on Nov. 10, 2009 | Joined: Aug. 2007 | Days Active: 575
Join to learn more about allsmiles England, United Kingdom | Male | Posts: 8,896 | Points: 15,976
sakurag


Soothsayer

Patron
Reply
This could also be done with a boolean.  However, the solution also provided doesn't need extra variables.

-------
I've got spurs that jingle jangle jingle.
As I go riding merrily along.
And they sing, "Oh, ain't you glad you're single?"
And that song ain't so very far from wrong.

7:16 am on Nov. 10, 2009 | Joined: Oct. 2002 | Days Active: 865
Join to learn more about sakurag Washington, United States | Straight Male | Posts: 2,822 | Points: 12,309
( King Kong )


Ghostbuster

Patron
Reply
Quote: from allsmiles at 3:14 pm on Nov. 10, 2009

It is a while loop...

my brain must be asleep, sorry

-------
Pandora didn't think outside the box


7:18 am on Nov. 10, 2009 | Joined: Feb. 2006 | Days Active: 1,094
Join to learn more about King Kong Wales | Straight Male | Posts: 26,390 | Points: 38,429
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic