java problem

Status
Not open for further replies.

lizalaz

Beta member
Messages
4
write a simple GUI program that calculate the area of a circle given a radious.

please help.
 
That is pretty easy, just get the radius and use pi*r^2 to calculate the area and then output it.
 
import the JOptionPane library.

have the user input some radius ->
radius = JOptionPane.showInputDialog ( "Enter Radius" )

Calculate it with the above equation

print it out ->
JOptionPane.showMessageDialog ( null, "The radius is " + result, "Result", JOptionPane.PLAIN_MESSAGE )
 
import javax.swing.JOptionPane;

public class Class1 {

public static void main(String args[]) {
int radius = JOptionPane.showInputDialog(null, "Enter the radius");
radius = Math.PI * radius * radius;
JOptionPane.showMessageDialog(null, radius ,"Information", JOptionPane.INFORMATION_MESSAGE);



}
}


I made that in the middle of history, so I don't know if it works. I tried to keep it simple.
 
Status
Not open for further replies.
Back
Top Bottom