Advertisement
JackHoughton00

Perfect Square

Mar 5th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package perfectsquare;
  2. import java.util.Scanner;
  3. public class PerfectSquare {
  4.  
  5. public static void main(String[] args) {
  6. Scanner input = new Scanner(System.in);
  7. System.out.print("This program will decide if a number you enter is a perfect square.");
  8. System.out.print("\nPlease input a number: ");
  9. double num, square = 0;
  10. num = input.nextInt();
  11. square = (double) Math.sqrt(num);
  12. square = (int)square;
  13. square = Math.pow(square,2);
  14. if (square ==num){
  15. System.out.print("This number is a perfect sqaure.");
  16. }else{
  17. System.out.println("This number is not a perfect square");
  18. }
  19. }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement