Write a java program to check if number is perfect square or not ........Wrong answer or no answer will be reported......
Answers
Answered by
1
Write a Java program to test if a given number (positive integer ) is a perfect square or not.
Input number: 3 Output: 1 2 3 8 9 4 7 6 5
Pictorial Presentation:

Sample Solution:
Java Code:
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Input a positive integer: "); int n = in .nextInt(); System.out.print("Is the said number perfect square? " + is_Perfect_Square(n)); } public static boolean is_Perfect_Square(int n) { int x = n % 10; if (x == 2 || x == 3 || x == 7 || x == 8) { return false; } for (int i = 0; i <= n / 2 + 1; i++) { if ((long) i * i == n) { return true; } } return false; } }
Answered by
6
Answer:
hope it's help you mate
Attachments:
Similar questions
English,
4 months ago
English,
8 months ago
Social Sciences,
8 months ago
Math,
1 year ago
History,
1 year ago