In this tutorial, you will learn how to square a number in java. So Let’s get started.
In Java, there are at least two ways to square a number:
- Multiply the number by itself
- Call the Math.pow function
These approaches are demonstrated in the following instances.
- Square a number by multiplying it by itself:
This is how you square a number by multiplying it by itself:
int i = 2; int square = i * i;