I am sure most of you have encountered this program. It is probably pretty easy for most of you.
Problem: I have gotten it to ask me to "Please Enter Radius". I enter a Radius of 5, for example, and it gives me an Area of 0.0. In the program I declared radius as "int radius=0" No matter what number I put in when it prompts me to enter radius, it will only compute using "0". How do I get it to give me the area based on what I enter at the prompt? Here is my program:
import java.io.*;
public class Project_2 {
static final double PI=3.141592653589793;
public static void main(String[] args) {
// TODO, add your application code
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(stdin);
int radius=5;
double area=PI*(radius*radius);
String str1;
try{System.out.println("Please Enter Radius: ");
str1=console.readLine();
radius=Integer.parseInt(str1);
//Ignore the next 5 lines for now.
}catch(IOException e)
{System.out.println("Input error");
}catch(NumberFormatException e) {System.out.println(e.getMessage()+ "is not numeric");
area=PI*(radius*radius); //Enter your formula for the area here
}System.out.println("The Area is: " + (area));
} //Ends main
} //Ends Proj_2 Class
