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

1. Member
Join Date
Oct 2008
Posts
7
Rep Power
0

## 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)?
Last edited by mk3823; 10-23-2008 at 05:14 PM.

2. 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?

3. Senior Member
Join Date
Sep 2008
Posts
564
Rep Power
6
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.

4. Senior Member
Join Date
Aug 2008
Posts
384
Rep Power
6
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.

5. Member
Join Date
Oct 2008
Posts
7
Rep Power
0

## 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.

6. The code you have there, is that everything you have written so far??

7. Member
Join Date
Oct 2008
Posts
7
Rep Power
0

## Program

No, just part of it.

8. Post what you have so we can have a look at it

see what we can help with

9. Member
Join Date
Oct 2008
Posts
7
Rep Power
0
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. 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.

Java 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;
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•