Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This program inputs a number and checks whether the number entered is a perfect square or not.
- */
- import java.util.Scanner;
- public class Perfect_Square
- {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("Please enter a number.");
- int num=sc.nextInt();
- int i,prod,flag=0;
- for(i=1;i<=num;i++)
- {
- prod=i*i;
- if(prod==num)
- {
- flag=1;
- break;
- }
- }
- if(flag==1)
- {
- System.out.println(num+" is a perfect square.");
- }
- else
- {
- System.out.println(num+" is not a perfect square.");
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment