Write a Java program to test if a given number (positive integer ) is a perfect square or not.

 /* Write a Java program to test if a given number (positive integer ) is a

perfect square or not.

Expected Output:

Input a positive integer: 6

Is the said number perfect square? false */


import java.util.*;

class Thirteen

{

public static void main(String arg[])

{

Scanner obj = new Scanner(System.in); 

int no, a, flag=0;


System.out.print("\n Enter any positive number to cheak \n that number is perfect square or not : ");

no = obj.nextInt();


outer:

for (int i=1 ; i<=no ; i++ ) 

{

a = i * i;

if(no == a)

{

flag = 1;

break outer;

}

}

if(flag == 1)

{

System.out.println("\n\t => Enterd number is perfect square <=");

}

else

{

System.out.println("\n\t => Enterd number is not perfect square <=");

}

}

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.