键盘输入
import java.util.Scanner;
/*
计算圆的周长和面积。键盘输入
*/
public class Test {
public static void main(String[] args) throws Exception {
Scanner sr = new Scanner(System.in);
final double pi = 3.1415926;
System.out.print("输入半径r:");
double r = sr.nextDouble();
System.out.println("周长为:"+(2*pi*r));
System.out.println("面积为:"+(pi*r*r));
}
}
随机数
public class Test {
public static void main(String[] args) throws Exception {
Random r = new Random();
int x = r.nextInt(10);
System.out.println(x);
}
}