Wednesday, 25 December 2013

JAVA: Check the number if its perfect square or not.



import java.util.*;
import java.io.*;
public class perfectSquare {

    public static void main(String args[]) throws NumberFormatException, IOException{
       
        BufferedReader as = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(as.readLine());
        boolean y = true;
    //124System.out.println(x);
        for(int i=0; i<=x/2; i++){
            if(i*i <= x){
            if(x == (i*i)){
                System.out.println(x+ " is a perfect square");
                y = false;
                break;
               
            }
            }
        }
       
        if(y == true){
            System.out.println(x+ " is not a perfect square");   
           
        }
       
    }
   
}

No comments:

Post a Comment