Results 1 to 10 of 10
- 10-22-2008, 10:11 PM #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 04:14 PM.
- 10-22-2008, 11:10 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?
- 10-22-2008, 11:13 PM #3
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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 #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
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.
I die a little on the inside...
Every time I get shot.
- 10-23-2008, 04:09 PM #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.
- 10-23-2008, 04:36 PM #6
The code you have there, is that everything you have written so far??
- 10-23-2008, 09:27 PM #7
Member
- Join Date
- Oct 2008
- Posts
- 7
- Rep Power
- 0
Program
No, just part of it.
- 10-23-2008, 09:53 PM #8
Post what you have so we can have a look at it
see what we can help with
- 10-23-2008, 09:58 PM #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-24-2008, 11:13 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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; }
Similar Threads
-
writing to a excel file from java program
By priyankabhar in forum New To JavaReplies: 6Last Post: 03-15-2012, 04:29 PM -
writing a program launcher (or Timer)
By Farzaneh in forum Threads and SynchronizationReplies: 3Last Post: 02-17-2009, 09:00 AM -
how begin with writing a new program ?
By dimitrist in forum New To JavaReplies: 11Last Post: 05-13-2008, 03:49 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Help needed writing a program...
By Francis in forum New To JavaReplies: 2Last Post: 11-22-2007, 02:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks