forked from pandeyprem/DSA-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmycode1
More file actions
26 lines (26 loc) · 892 Bytes
/
mycode1
File metadata and controls
26 lines (26 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner;
public class CheckPerfectSquareExample1
{
//user-defined method that checks the number is perfect square or not
static boolean checkPerfectSquare(double number)
{
//calculating the square root of the given number
double sqrt=Math.sqrt(number);
//finds the floor value of the square root and comparing it with zero
return ((sqrt - Math.floor(sqrt)) == 0);
}
//main method
public static void main(String[] args)
{
System.out.print("Enter any number: ");
//object of the Scanner class
Scanner sc=new Scanner(System.in);
//reading a number of type double from the user
double number=sc.nextDouble();
//calling the user defined method
if (checkPerfectSquare(number))
System.out.print("Yes, the given number is perfect square.");
else
System.out.print("No, the given number is not perfect square.");
}
}