//分别用命令行参数,Scanner,JOptionPane和IO流实现对圆的面积和周长的求解
BufferedReader字符流
System.in字节流
InputStreamReader字节流转字符流
BufferedReader的read()是把第一个字符的ASCLL码赋值给变量
rreadLine()每次读回来的都是一行字符串
package firsthomework;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Circle {
public static void main(String[] args) throws IOException {
//命令行参数
int r1 = Integer.parseInt(args[0]);
System.out.println("圆的面积为"+Math.PI*r1*r1);
System.out.println("圆的周长为"+Math.PI*2*r1);
Scanner sc = new Scanner(System.in);
System.out.println("输入圆的半径:");
int r = sc.nextInt();
System.out.println("圆的面积为"+Math.PI*r*r);
System.out.println("圆的周长为"+Math.PI*2*r);
String s = JOptionPane.showInputDialog(null,"请输入圆的半径:\n","圆",JOptionPane.PLAIN_MESSAGE);
r = Integer.parseInt(s);
JOptionPane.showMessageDialog(null,"圆的周长为:"+Math.PI*2*r, "圆", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,"圆的面积为:"+Math.PI*r*r, "圆", JOptionPane.INFORMATION_MESSAGE);
System.out.println("输入圆的半径:");
BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
String s1 = br.readLine();
r = Integer.parseInt(s1);
System.out.println("圆的面积为"+Math.PI*r*r);
System.out.println("圆的周长为"+Math.PI*2*r);
}
}