loops

Reply

Join Date: Oct 2006
Posts: 1
Reputation: ThUgLoRd is an unknown quantity at this point 
Solved Threads: 0
ThUgLoRd ThUgLoRd is offline Offline
Newbie Poster

loops

 
0
  #1
Oct 13th, 2006
ok i just started loops in my java class and im stuck on getting this loop working i dunno what all math to do to get these numbers for the output
97, 84, 72, 61, 51, ... 1
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 101
Reputation: cms271828 is an unknown quantity at this point 
Solved Threads: 4
cms271828 cms271828 is offline Offline
Junior Poster

Re: loops

 
0
  #2
Oct 13th, 2006
try this...

int diff=14
for(int lp=97;lp>0;lp-=diff)
{
System.out.println(lp);
diff--;
}

try that, think it should work
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 13
Reputation: Goitse is an unknown quantity at this point 
Solved Threads: 0
Goitse Goitse is offline Offline
Newbie Poster

Re: loops

 
0
  #3
Oct 20th, 2006
The solution that you were given does not seem to work if I use it, so I decided to use another method using a while loop and the instructions are as follows

int i = 97;
int j = 14;

while(j > 0)
{
System.out.println(+ i);
j--;
i = i - j;
}
This solution will definately work, try it and you will see.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 89
Reputation: TylerSBreton is an unknown quantity at this point 
Solved Threads: 3
TylerSBreton's Avatar
TylerSBreton TylerSBreton is offline Offline
Junior Poster in Training

Re: loops

 
0
  #4
Oct 20th, 2006
The first implementation doesnt work because diff ends up becoming negative before the value reaches 0. Should be an infinite loop if my quick glance is correct.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 101
Reputation: cms271828 is an unknown quantity at this point 
Solved Threads: 4
cms271828 cms271828 is offline Offline
Junior Poster

Re: loops

 
0
  #5
Oct 21st, 2006
Well I just took a look at the program...
The numbers 97, 84, 72, 61, 51, ... 1 are wrong.
It doesn't end at 1, and it doesnt actually go negative, which is why my loop is infinite.
So depends where you want the loop to end, the smallest it gets to is 6. So you could end it at 6.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: bommavj is an unknown quantity at this point 
Solved Threads: 0
bommavj bommavj is offline Offline
Newbie Poster

Re: loops

 
0
  #6
Oct 23rd, 2006
Originally Posted by ThUgLoRd View Post
ok i just started loops in my java class and im stuck on getting this loop working i dunno what all math to do to get these numbers for the output
97, 84, 72, 61, 51, ... 1

class Loops
{
public static void main(String[] args)
{
for(int i=97;i>0;i--)
{
for(int j=13;j>0;j--)
{
System.out.print(i+" ");
i=i-j;
//System.out.println(j);
}
break;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: bommavj is an unknown quantity at this point 
Solved Threads: 0
bommavj bommavj is offline Offline
Newbie Poster

Re: loops

 
0
  #7
Oct 23rd, 2006
this is my ID: bommavj@gmail.com

my name is vijay if u wanna any help send me queries...


yours vijay....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC