Squaring numbers

I need to make a program where numbers from 1-12 will be squared. It needs to be in chart form. Any ideas? I'm still getting used to Java.ex: NumberSquare112439
[196 byte] By [Bigfoot245a] at [2007-11-27 6:43:35]
# 1
think loop...
jwentinga at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 2
Think for loop.Initialize a counter variable to 1 and keep looping while it's <= 12.You'll probably think System.out.println() is fine for writing the chart. If not, look at the NumberFormat class.
OleVVa at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 3
yea but how do u get it in chart form?
Bigfoot245a at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 4
> yea but how do u get it in chart form?Just print out the loop counter, then a space and the square. If you want something more complicated than that you'll need to describe what you want.
hunter9000a at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 5
Define "chart form"... do you mean snazzy graphics or a simple text "bar chart".
corlettka at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 6
sorry, just a basic chart like a showed in the example, thanks for your help.
Bigfoot245a at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 7

something like

Sytem.out.println("1" + "\t" + 2 + "\t");

Sytem.out.println("3" + "\t" + 3 + "\t");

//etc

Jamwaa at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 8

ok, right now I have this:

System.out.println("Number\n" + Number);

System.out.println("Square\n" + Number * Number);

and the ouput looks lik this:

Number

1

Square

1

Number

2

Square

4

I need it like this

Number Square

11

Bigfoot245a at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 9

> ok, right now I have this:

>

> System.out.println("Number\n" + Number);

> System.out.println("Square\n" + Number * Number);

>

> and the ouput looks lik this:

>

> Number

> 1

> Square

> 1

> Number

> 2

> Square

> 4

>

> I need it like this

>

> Number Square

> 11

Do you understand what things are before you write them ?Do you know what the \n does ?

Aknibbsa at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 10

> ok, right now I have this:

>

> System.out.println("Number\n" + Number);

> System.out.println("Square\n" + Number * Number);

>

> and the ouput looks lik this:

>

> Number

> 1

> Square

> 1

> Number

> 2

> Square

> 4

>

> I need it like this

>

> Number Square

> 11

Just print "Number Square" once, then print the index and square in the loop. Look up the difference between print() and println(): http://java.sun.com/j2se/1.5.0/docs/api/java/io/PrintStream.html

hunter9000a at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 11
As I posted before, use "\t" instead of "\n"
Jamwaa at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...
# 12

System.out.printf("%10s | %10s%n","Number","Square");

for(int i = 1; i <= 12; i++)

{

System.out.printf("%10d | %10d%n", i, i*i);

}

//RESULTS

Number |Square

1 | 1

2 | 4

3 | 9

4 | 16

5 | 25

6 | 36

7 | 49

8 | 64

9 | 81

10 |100

11 |121

12 |144

I love printf for aligning things nicely

SomeoneElsea at 2007-7-12 18:14:31 > top of Java-index,Java Essentials,Java Programming...