Program to check perfect square in java

Simple Java program to check whether a number is perfect square or not | Java Programming

import java.util.Scanner;


public class checkPerfectSquare{

public static void main(String []args){

Scanner sc = new Scanner(System.in);

System.out.println("Enter a number to check: ");

double num = sc.nextDouble();

sc.close();

double d=Math.sqrt(num);

if (d-Math.floor(d)==0){

System.out.print(num+ " is a perfect square number.");

}

else{

System.out.print(num+ " is not a perfect square number.");

}

}

}

14 views

Recent Posts

See All

"Believe you can and you're halfway there"