#### Square and Cube coderinme

How to Square A Number

To square a number, just multiply it by itself

3 Squared = 32 = 3 × 3 = 9

4 Squared = 42 = 4 × 4 = 16

5 Squared = 52 = 5 × 5 = 25

How to Cube A Number

To cube a number, just use it in a multiplication 3 times

4 cubed = 43 = 4 × 4 × 4 = 64

5 cubed = 53 = 5 × 5 × 5 = 125

6 cubed = 63 = 6 × 6 × 6 = 216

Write Java program to print the square and cube for the numbers 1 to 5.

```
import java.io.*;
public class Q1
{
public static void main(String[] args)
{
for(int i=1;i<=5;i++)
{
System.out.println("Number is: "+i+" Its Square is : "+Math.pow(i,2)+" and Cube is :"+Math.pow(i,3));
}
}
}
```

For more programs on Java, visit our Java Archives

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme