Categories: softare development

Check if Given Number is a Perfect Square in Java

A perfect square is a number that is made by squaring a whole number.

For example:

16 is a perfect square because 42 = 16.
25 is also a perfect square because 52 = 25.

And it goes on and on … .

So now let’s determine in Java if a given number is perfect square or not.

public class checkPerfectSquare(){

public static void main(String args[]){
 System.out.println(isPerfectSquare(16));
}
public static String isPerfectSquare(int n) {
  
 double sqrt=Math.sqrt(n);   
        if ((sqrt - Math.floor(sqrt)) == 0){
 return "Integer "+ n+ " is a Perfect Square";
 }else{
 return "Integer "+ n+ " is NOT a Perfect Square";
    }

 }
}

//16 is a Perfect Square

Check if a Number in Palindrome in Java

Recent Posts

Getting Started With TensorFlow

"The journey of a thousand miles begins with a single step." — Lao Tzu Welcome…

3 days ago

Your Mind is a Supercomputer

We often describe ourselves as "processing" information, "rebooting" after a bad day, or feeling "overloaded"…

6 days ago

What is a QR Code And How to Create One

QR codes have evolved from a niche tracking technology to an indispensable digital connector, seamlessly…

2 weeks ago

Will AI Replace Software Developers?

Artificial Intelligence (AI) has made remarkable progress in recent years, transforming industries such as healthcare,…

3 weeks ago

Can Tech Really Solve Climate Change—Or Is It Just Greenwashing?

Climate change is one of the most pressing challenges of our time, with rising global…

4 weeks ago

The Inevitable Rise of Transhumanism

In the last few decades, technology has become so embedded in our daily lives that…

1 month ago