-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolved the issue and added code of squaring of any number in java
- Loading branch information
1 parent
2ca567d
commit 085394b
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//Hey,This is the java code for finding square of any number! - NikhilSharma | ||
|
||
import java.util.*; | ||
|
||
class SquareOfNum { | ||
public static void main(String[] args) { | ||
//Taking input number from the user using scanner class | ||
Scanner sc = new Scanner(System.in); | ||
System.out.print("Enter number : "); | ||
long num = sc.nextLong(); | ||
|
||
|
||
/* | ||
created generateSquare function that takes num as input | ||
and return squared value of num as output | ||
*/ | ||
|
||
long squaredNum = generateSquare(num); | ||
|
||
//printing the squared value to screen | ||
System.out.println("Squared number : " + squaredNum); | ||
} | ||
|
||
static long generateSquare(long num){ | ||
/* | ||
we can square the number in many ways: | ||
|
||
1. just multiplying the number with itself - num*num | ||
2. using pow function in math class - Math.pow(num,2); | ||
|
||
*/ | ||
|
||
return num * num; | ||
} | ||
} |