沒有輸入啊,你看看
鎮(zhèn)遠網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,鎮(zhèn)遠網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為鎮(zhèn)遠超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的鎮(zhèn)遠做網(wǎng)站的公司定做!
import java.util.*;
public class Volume
{
public static void main(String [] args)
{
System.out.print("請輸入r:");
Scanner reader=new Scanner(System.in);
double r=0,v=0;
r=reader.nextDouble();
v=4*3.14159/3*r*r*r;
System.out.println("球體積為:"+v);
}
}
abstract?class?Shape{
protected?static?final?double?PI?=?3.14;
abstract?double?volume();
}
class?Spherosome?extends?Shape{
private?double?radius;
public?Spherosome(double?radius){
this.radius?=?radius;
}
@Override
double?volume()?{
// 圓球的體積公式=(4/3)πr^3
return?PI*radius*radius*radius*4/3;
}
}
class?Cone?extends?Shape{
private?double?radius,?height;
public?Cone(double?radius,?double?height){
this.radius?=?radius;
this.height?=?height;
}
@Override
double?volume()?{
// 圓錐的體積公式=(1/3)hπr^2
return?height?*?PI?*?radius?*?radius?/?3;
}
}
public?class?Test?{
public?void?testSpherosome(double?radius){
Spherosome?spherosome?=?new?Spherosome(radius);
System.out.println("圓球的半徑:"?+?radius?+?",?圓球的體積:"?+?spherosome.volume());
}
public?void?testCone(double?radius,?double?height){
Cone?cone?=?new?Cone(radius,?height);
System.out.println("圓錐的底半徑:"?+?radius?+?",高:"?+?height?+?",?圓錐的體積:"?+?cone.volume());
}
public?static?void?main(String[]?args)?{
Test?test?=?new?Test();
test.testSpherosome(1);
test.testCone(1,?1);
}
}
import?java.util.Scanner;
class?Test{
public?static?void?main(String[]?args){
Scanner?sc?=?new?Scanner(System.in);
double?r?=?sc.nextDouble();//球的半徑r
double?v?=?4.0/3.0*3.14*r*r*r;//球的體積v
System.out.println(v);//輸出體積
}
}
//這個夠簡單吧?希望采納喲
參考一下:
/*
*已知圓球體積為4/3πr3,試編寫一個程序,輸入圓球半徑,經(jīng)過計算輸出圓球的體積。
*從命令窗輸入
*/?
import?java.util.Scanner;??????????????
public?class?Volume{?????????????????????????//定義Java中類成員變量
public?static?void?main(String?args[]){?????????????//main()方法體,一個java?application程序的入口
Scanner?s=new?Scanner(System.in);
System.out.println("請輸入要求體積的圓球的半徑r");??????????//輸出提示內(nèi)容
double?r=s.nextDouble();???????????//定義一個double型變量
double?v;??????????????//定義一個double?型變量
v=4*Math.PI*Math.pow(r,3)/3;????????//運算表達式
System.out.println("求得圓球的體積為"+v);??????//輸出計算結(jié)果,并在開頭輸出"求得圓球的體積為"
?
}
}
import?java.util.Scanner;
/**
*?計算球的體積
*?
*?@author?young
*
*/
public?class?Volume?{
public?static?void?main(String[]?args)?{
System.out.print("請輸入r:");
Scanner?reader?=?new?Scanner(System.in);
double?r?=?0,?v?=?0;
r?=?reader.nextDouble();
v?=?4?*?3.14159?/?3?*?r?*?r?*?r;
System.out.println("球體積為:"?+?String.format("%.2f",?v));
}
}
class A{//類A計算立方體體積 }class B{//類A計算球體體積 } class C{//類A計算圓柱體積 }//主類public class test{ static{ System.out.println("請輸入1、2、3對應(yīng)立方體、球體和圓柱的體積計算..."); }public static void main(String args[]){ if(args.length1 || Integer.parseint(args[0])1|| Integer.parseint(args[0])3){//判斷輸入是否符合標(biāo)準 System.out.println("錯誤的選擇,程序自動退出.."); System.exit(1); } else{ int x = Integer.parseint(args[0]) ; switch(x){ case 1: //調(diào)用A類 case 2: //調(diào)用B類 defualt: //調(diào)用C類 } } }}