top of page
Click here to go to the home page of AskTheCode.

Program to check perfect square in java

Team ATC

Updated: Apr 3, 2021

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

 

Problem:

Write a program to check whether a given number is a perfect square or not a perfect square, in java.

 

Code:

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.");
        }
     }
}

Recent Posts

See All

Comments


bottom of page