Results 1 to 10 of 10
  1. #1
    mk3823 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

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

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

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

    Default

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

    Default

    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.

  5. #5
    mk3823 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default 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. #6
    markious's Avatar
    markious is offline Member
    Join Date
    Oct 2008
    Posts
    27
    Rep Power
    0

    Default

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

  7. #7
    mk3823 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default Program

    No, just part of it.

  8. #8
    markious's Avatar
    markious is offline Member
    Join Date
    Oct 2008
    Posts
    27
    Rep Power
    0

    Default

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

    see what we can help with

  9. #9
    mk3823 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default

    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. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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

  1. writing to a excel file from java program
    By priyankabhar in forum New To Java
    Replies: 15
    Last Post: 01-17-2014, 12:39 PM
  2. writing a program launcher (or Timer)
    By Farzaneh in forum Threads and Synchronization
    Replies: 3
    Last Post: 02-17-2009, 09:00 AM
  3. how begin with writing a new program ?
    By dimitrist in forum New To Java
    Replies: 11
    Last Post: 05-13-2008, 03:49 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Help needed writing a program...
    By Francis in forum New To Java
    Replies: 2
    Last Post: 11-22-2007, 02:03 PM

Posting Permissions

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