0% found this document useful (0 votes)
27 views1 page

Perfect Square

The Java program checks if a given number is a perfect square. It prompts the user to enter a number and iterates from 1 to half of that number, checking if the square of any integer equals the input. If a perfect square is found, it prints the result; otherwise, it indicates that the number is not a perfect square.

Uploaded by

fivopew106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Perfect Square

The Java program checks if a given number is a perfect square. It prompts the user to enter a number and iterates from 1 to half of that number, checking if the square of any integer equals the input. If a perfect square is found, it prints the result; otherwise, it indicates that the number is not a perfect square.

Uploaded by

fivopew106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import java.util.

*;
public class perfectsq {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter number:");
int n=sc.nextInt();
for(int i=1;i<=n/2;i++)
{
if(i*i==n)
{
System.out.println("Entered no. is a perfect square of
"+i);
System.exit(0);
}
}
System.out.println("Entered no. is not a perfect square");
}
}

You might also like