Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package perfect.square;
- import javax.swing.JOptionPane;
- import java.lang.Math;
- /**
- *
- * @author Monty
- */
- public class PerfectSquare {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- double innum, root, square;
- int inum, num2;
- String num = JOptionPane.showInputDialog("Input a number");
- inum = Integer.parseInt(num);
- innum = (double)inum;
- root = Math.sqrt(innum);
- num2 = (int)root;
- square = Math.pow(num2, 2);
- if (innum == square) {
- System.out.println("Number is a perfect square.");
- } else{
- System.out.print("Number is not a perfect square");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment