Friday, June 1, 2012

Square a number in JAVA.

   Another simple program that will output the square of any input number. Im not in front of my JAVA application but i am pretty sure that it will work properly. This program will show the simple string to double type variable conversion in java programming.




Code:
import javax.swing.JOptionPane;

public class Square{
public static void main (String [] args){
     String number;
     Double num, squareofNumber;

number=JOptionPane.showInputDialog("Enter a number: ");
//convert string to double
num=Double.ParseDouble(number);
squareofNumber=num*num;

JOptionPane.showMessageDialog(null, "The square of the number you entered is "+square);
   }
}

No comments:

Post a Comment