Wriye a java program to check wether the number is perfect square or not ........Wrong anwer or no anwer will be reported
Answers
Answer:
•Take the square root of the number.
•Take floor/ceil/round of the square root which we got in step 1
•Subtract value we got in step 2 from the square root.
•If the output of step 3 is 0 then the number is perfect square else not.
Explanation:
hope this is useful for u
Answer:
// Finding whether a number is a perfect square number in Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PerfectSquareNumber {
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter an integer : ");
int number = Integer.parseInt(reader.readLine());
int sqrt = (int) Math.sqrt(number);
if(sqrt*sqrt == number) {
System.out.println(number+" is a perfect square number!");
}else {
System.out.println(number+" is NOT a perfect square number!");
}
}
}