# Thread: Triangle program for beginner

1. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

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

3. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

## Re: Triangle program for beginner

no idea what it would be

4. ## Re: Triangle program for beginner

Originally Posted by shawnx715
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

5. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

## Re: Triangle program for beginner

what is i?

i know how many zeros there are on each line

6. ## 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. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

## Re: Triangle program for beginner

Originally Posted by Norm
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. ## 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. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

## Re: Triangle program for beginner

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

10. ## 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. ## Re: Triangle program for beginner

Originally Posted by shawnx715
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. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

doesnt work

13. ## 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. ## 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. ## Re: Triangle program for beginner

Just got this via PM:
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 01:38 PM.

16. ## 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. Member
Join Date
Nov 2011
Posts
7
Rep Power
0

## Re: Triangle program for beginner

so how should i do this?

18. ## Re: Triangle program for beginner

Originally Posted by shawnx715
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. ## 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.

#### Posting Permissions

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