java计算圆形的面积,java计算圆形面积,如下代码首先我们要求用户
分享于 点击 19194 次 点评:199
java计算圆形的面积,java计算圆形面积,如下代码首先我们要求用户
如下代码首先我们要求用户输入圆形的半径,然后计算圆形的面积:
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;/** * * @author byrx.net */public class Main { /** * 计算圆形的面积 */ public static void main(String[] args) { int radius = 0; System.out.println("Please enter the radius of a circle"); BufferedReader reader = null; try { //get the radius from user input reader = new BufferedReader(new InputStreamReader(System.in)); radius = Integer.parseInt(reader.readLine()); } catch (NumberFormatException nfe) { nfe.printStackTrace(); System.exit(0); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } finally { try { reader.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } double area = Math.PI * radius * radius; System.out.println("The circle area is " + area); }}
用户点评