here is my code

import javax.swing.*;
import java.text.DecimalFormat;

class method {
private static void start() {
JOptionPane.showMessageDialog(null," Area of a Circle");
String n = JOptionPane.showInputDialog(null,"Enter a Number");
int num = Integer.parseInt(n);
DecimalFormat twoDigit= new DecimalFormat("0.00");
double form1 =  3.14 * (num*2);
JOptionPane.showMessageDialog(null,"… is "+twoDigit.format(form1));

}


public static void main(String[] args) {


   start();

String ipt = JOptionPane.showInputDialog("enter num");
int iptipt = Integer.parseInt(ipt);

if(iptipt==1){

method.start();
}


}}

my code is working but not the way i want. i want to display just the anz of the method start but In main in if statement "if(iptipt==1){metod.start();}"
it again calls the whole method instead of giving the specfic anz.can any any correct it

}

The area of a circle is 3.14*radius*radius rather than 3.14 *(radius*2)
The following static method start() may do one run to calculate the area of a circle.

private static void start() {
String n = JOptionPane.showInputDialog(null,"Enter the radius to calculate the area of a Circle");
int num = Integer.parseInt(n);
DecimalFormat twoDigit= new DecimalFormat("0.00");
double form1 = 3.14 * (num*num);
JOptionPane.showMessageDialog(null,"The area of the circle is "+ twoDigit.format(form1));
}

extemer, can you clearify your intention: What do you want to do with this program?
1. after one run, you want to finish the program's execution, or
2. after one run, you want to do another run until client clicks the cancel button to stop the execution of this program?

i want value assign to form1 in the start method to call in main not calling the ful method

i want value assign to form1 in the start method to call in main not calling the ful method

Sorry, I'm not able to understand what you want. Can you explain it further please?
Do you want the start() method to return the value of form1 to its caller?

The only way that sentence makes sense is:

I want the value assigned to form1, in the start method, to get called in main but not call the whole method.

I could be way off though as it sounds....

Member Avatar for coil

I think what he's saying he wants to find the result of the calculation in the start() method but not show the dialogs.

In that case, create a separate method calculate() which just calculates what you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.