# Triangle program for beginner

• 11-14-2011, 10:37 PM
shawnx715
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
• 11-14-2011, 11:00 PM
JosAH
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
• 11-14-2011, 11:01 PM
shawnx715
Re: Triangle program for beginner
no idea what it would be
• 11-14-2011, 11:10 PM
JosAH
Re: Triangle program for beginner
Quote:

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
• 11-14-2011, 11:12 PM
shawnx715
Re: Triangle program for beginner
what is i?

i know how many zeros there are on each line
• 11-14-2011, 11:12 PM
Norm
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?
• 11-14-2011, 11:21 PM
shawnx715
Re: Triangle program for beginner
Quote:

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
• 11-14-2011, 11:40 PM
Norm
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.
• 11-14-2011, 11:43 PM
shawnx715
Re: Triangle program for beginner
for(int power = 0; power<13; power ++){
system.out.println(''+mathe.pow(10, power.)
}
• 11-14-2011, 11:55 PM
Norm
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-15-2011, 12:00 AM
Junky
Re: Triangle program for beginner
Quote:

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!
• 11-15-2011, 12:03 AM
shawnx715
Re: Triangle program for beginner
doesnt work
• 11-15-2011, 12:05 AM
Junky
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?
• 11-15-2011, 12:05 AM
Norm
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
• 11-15-2011, 12:31 AM
Norm
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.

• 11-15-2011, 12:38 AM
Junky
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.
• 11-15-2011, 05:14 AM
shawnx715
Re: Triangle program for beginner
so how should i do this?
• 11-15-2011, 05:27 AM
Fubarable
Re: Triangle program for beginner
Quote:

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.
• 11-15-2011, 01:40 PM
Norm
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.