Skip to content

Commit

Permalink
resolved the issue and added code of squaring of any number in java
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilCode12 committed Oct 1, 2022
1 parent 2ca567d commit 085394b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Java/SquareOfNum.txt
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;
}
}

0 comments on commit 085394b

Please sign in to comment.