# Writing a program(HELP!! It's due tommorrow!!!!!)

• 10-22-2008, 10:11 PM
mk3823
Writing a program(HELP!! It's due tommorrow!!!!!)
Hey, I was wondering if you guys can help me with this program. I'm taking computer science AB and we were assigned to this program.

In this program, we had to use the three loops, the for, the while, and the do-while loops to print out the #'s 1-10 squared without the multiplying and without math classes. Well, on the while loop, I have print out 1-10 squared in reverse. So far, not going well:( I finished the rest. Anyway, here's the code:

n = 100;
int num=19;
seq=n-num;
System.out.println(100);//prints 100
while(n>=1)
{
num-=2;//decreases 19 by 2
seq=n-num;//decreases n by num
System.out.println(num-2);
}
Any suggestions(it's due tommorrow)?
• 10-22-2008, 11:10 PM
Norm
What does the code you've posted supposed to do now? I can't tell from your comments in the code (there aren't any)
What parts do you need to finish?
• 10-22-2008, 11:13 PM
emceenugget
what problem are you having?
are you allowed to hard code values as you have, such as n=100, num=19 and System.out.println(100)?
if what you're doing so far isn't working out for you, you can try doing it in increasing order first. then, doing it in reverse shouldn't be difficult.
• 10-23-2008, 08:45 AM
Supamagier
Oh, and really, saying it's due tomorrow a couple of times won't help at all, it just annoys us. But, well, as it's tomorrow today, I hope, for you, you managed to do this.
• 10-23-2008, 04:09 PM
mk3823
Sorry
I wasn't trying to annoy you, I was trying to get your attention. And as for the second I "supposedly" wrote......... I don't know how it got there.
• 10-23-2008, 04:36 PM
markious
The code you have there, is that everything you have written so far??
• 10-23-2008, 09:27 PM
mk3823
Program
No, just part of it.
• 10-23-2008, 09:53 PM
markious
Post what you have so we can have a look at it

see what we can help with
• 10-23-2008, 09:58 PM
mk3823
public class Triple
{
public static void main(String args[])
{
int n=0;
int seq=n+1;
for(n=1;n<=100;n=n+seq)
{
System.out.println(n);
seq+=2;
}

n = 0;
seq=n+1;
do
{
seq+=2;
System.out.println(n+1);
n=n+seq;

}
while(n<=100);

n = 0;//notice that I tried to print out the numbers in regular order
seq=n+1;
while(n<=100)
{
seq+=2;
System.out.println(n+1);
n=n+seq;
}
}
}

This program is a little different because I tried messing with it.
• 10-24-2008, 11:13 AM
Eranga
May be you have submitted the assignment.

Anyway you should use simple logic to do this. Following code segment do that using a for loop.

Code:

```        int result = 0;                 for(int i = 1; i <= 10; i++) {             for(int j = 0; j < i; j++) {                 result += i;             }             System.out.println(result);             result = 0;         }```