Results 1 to 19 of 19
  1. #1
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Triangle program for beginner

    I have this problem. I just started taking a programmign class, and i'm so lost in this class...i need help with this problem

    the program prints the following values

    1
    10
    100
    1000
    10000
    100000
    1000000
    10000000
    100000000
    1000000000
    10000000000
    100000000000

    i have to write the algorithm for this and the program itself...if someone cane help me with this, i would be very thankful

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Triangle program for beginner

    Suppose we give an index number to each row as follows: the first row get index number 0, the next row gets number 1, etc. My question to you: how may zeros are there on a line with index number i?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    no idea what it would be

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Triangle program for beginner

    Quote Originally Posted by shawnx715 View Post
    no idea what it would be
    How many zeros are there on the first line (the index value of that line is 0)?
    How many zeros are there on the second line (the index value of that line is 1)?
    How many zeros are there on the third line (the index value of that line is 2)?
    How many zeros are there on the fourth line (the index value of that line is 3)?

    How many zeros are there .. ... ..... ... (the index value of that line is i)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    what is i?

    i know how many zeros there are on each line

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    Do you have a piece of paper?
    Write the characters for triangle just like you put in the first post. But leave some room on the side.
    Now go down the side of the triangle you just wrote the characters for and place a row number/index next to each row. Start at the top with row 0, then 1 on the next row and so on until all the rows have numbers on them.
    Now look at any row, and see how many zeros are on that row. Look at the row number. What is the relationship between the number of zeros on a row and the row number you wrote at the side of the row?

  7. #7
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    Quote Originally Posted by Norm View Post
    Do you have a piece of paper?
    Write the characters for triangle just like you put in the first post. But leave some room on the side.
    Now go down the side of the triangle you just wrote the characters for and place a row number/index next to each row. Start at the top with row 0, then 1 on the next row and so on until all the rows have numbers on them.
    Now look at any row, and see how many zeros are on that row. Look at the row number. What is the relationship between the number of zeros on a row and the row number you wrote at the side of the row?
    the relationship is that the the numbers i wrote is the amount of zeros in the picture

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    Next you need to look at how to use a for loop and the print statement to print numbers all in a row.

  9. #9
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    for(int power = 0; power<13; power ++){
    system.out.println(''+mathe.pow(10, power.)
    }

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    What prints when you execute your code?

    Do you get compiler errors with your code?

    Why are you using the mathe.pow() method?

  11. #11
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Triangle program for beginner

    Quote Originally Posted by shawnx715 View Post
    no idea what it would be
    WOW!

    You just posted the expected output and are incapable of counting how many zeroes are on each line?

    WOW!

  12. #12
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    doesnt work

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Triangle program for beginner

    Well that provides a ton of valuable information. Do you think that posting your latest code, error messages and a detailed description of what happens when you run your program would help us? Or should we just guess?

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    Please explain. Copy and paste the full text of the errors here.

    Where did you get the code you posted in post#9?

    Do you know how to read the API doc where the classes and methods are defined? Here's a link:
    Java Platform SE 6

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    Just got this via PM:
    Quote Originally Posted by shawnx715
    i'd rather talk privately.

    this is what is says on the worksheet:

    1
    10
    100
    1000
    10000
    100000
    1000000
    10000000
    100000000
    1000000000
    10000000000
    100000000000

    implement a class

    public class Power Generator{
    public PowerGenerator (int aFactor) {...}
    public double nextPower (){...}
    }

    then supply a test class PowerGeneratorTest that calls system.out.println (myGnerator.nextPower ()) twelve times.
    Last edited by Norm; 11-15-2011 at 12:38 PM.

  16. #16
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Triangle program for beginner

    Oh, so this is not one of those Triangle shape programs. It simply requires the powers of 10 to be output. Well that is even easier.

  17. #17
    shawnx715 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: Triangle program for beginner

    so how should i do this?

  18. #18
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Triangle program for beginner

    Quote Originally Posted by shawnx715 View Post
    so how should i do this?
    Sorry to be blunt, but throughout this entire exercise, amazingly not once have you shown that you have put any thought into this project. I suggest that you re-read Norm's suggestions and then do this.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

    Default Re: Triangle program for beginner

    Show your code and the errors you are getting and explain how you are trying to generate the required printout.

Similar Threads

  1. Perimeter of a Triangle and Circle Program
    By Zora in forum New To Java
    Replies: 7
    Last Post: 10-13-2011, 03:43 AM
  2. triangle program
    By computerbum in forum New To Java
    Replies: 8
    Last Post: 03-02-2010, 04:55 AM
  3. Help with calculating triangle program
    By ALH813 in forum New To Java
    Replies: 5
    Last Post: 10-19-2009, 05:08 AM
  4. Errors in Program (Right Triangle)
    By SupaStudy in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 10:42 AM
  5. Triangle Sides program
    By jamesov89 in forum New To Java
    Replies: 6
    Last Post: 10-06-2008, 03:36 AM

Posting Permissions

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