例:编写程序,根据输入球体半径,计算体积并输出
import java.util.Scanner;//导包,导入Scanner类
public class volume {
public static void main(String[] args) {
System.out.println("请输入半径");
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
double PI=3.14;
double v=4/3*PI*r*r*r;
System.out.println("半径为"+r);
System.out.println("球体体积"+v);
}
}