Monty374

Perfect Square

Sep 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package perfect.square;
  2.  
  3. import javax.swing.JOptionPane;
  4. import java.lang.Math;
  5.  
  6. /**
  7. *
  8. * @author Monty
  9. */
  10. public class PerfectSquare {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args) {
  16. double innum, root, square;
  17. int inum, num2;
  18. String num = JOptionPane.showInputDialog("Input a number");
  19. inum = Integer.parseInt(num);
  20. innum = (double)inum;
  21. root = Math.sqrt(innum);
  22. num2 = (int)root;
  23. square = Math.pow(num2, 2);
  24.  
  25. if (innum == square) {
  26. System.out.println("Number is a perfect square.");
  27. } else{
  28. System.out.print("Number is not a perfect square");
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment