Write a program for a given number in perfect square or not
import java.util.Scanner; public class perfectsquare { public static void main(String[] args) { System.out.println("Enter a number"); Scanner sc=new Scanner(System.in); int num=sc.nextInt(); double num1=Math.sqrt(num); double num2=num1; if(num1==num2) System.out.println(num + "is a perfect square"); else System.out.println(num + "is not a perfect square"); } } Output: Enter a number 100 100 is a perfect square
No comments:
Post a Comment