# Programming a power table

• November 16th, 2010, 07:02 PM
Reynalto
Programming a power table
I'm a beginner at java and one of my assignments is to make a table like a times table but instead of a times table it's a power table
example:

1 2 3 4 5
2 4 8 16 25
3 9 27 81 243
4 16 64 256 1024
5 25 125 625 3125

I thought I had the right idea here but it doesn't seem to work the way i want it.

Code Java:

```{ int rows = 12; int columns = 12; for(int i=1;i<=rows;i++) { for(int j=1;j<=columns;j++) { System.out.printf("%5s",i^j); } System.out.print("\n"); } }```

how do I create a power table? I wish I could figure it out on my own and not ask others for help but I just can't seem to be able to figure it out.
• November 16th, 2010, 07:12 PM
copeg
Re: Programming a power table
The carot '^' operator is a bitwise XOR operator. Its more of an advanced topic, the results of which are not powers of. You might want to use Math.pow, or alternatively a loop where the value is multiplied iteratively.
• November 16th, 2010, 07:34 PM
Reynalto
Re: Programming a power table
Quote:

Originally Posted by copeg
The carot '^' operator is a bitwise XOR operator. Its more of an advanced topic, the results of which are not powers of. You might want to use Math.pow, or alternatively a loop where the value is multiplied iteratively.

I've replaced the "i^j" with Math.pow(i,j).

In the run window I get all of the values in double as Math.pow returns the numbers as type double. How can I convert it to int? I do it by type casting right? How do I do that again?
• November 16th, 2010, 07:51 PM
javapenguin
Re: Programming a power table