java問題..幫忙一下..很急
import java.io.*;
public class CalCir{
public static void main(String args[])throws IOException{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str;//nothing, just create a String object....
int i=0;//initial integer i
System.out.println("請輸入圓半徑");
str=buf.readLine();
i=Integer.parseInt(str);
if(i>0){
TestCalCir tcc=new TestCalCir();
tcc.cal(i);
}
else{
System.out.println("請輸入大於0的數字!");
}
}
}
class TestCalCir{
public void cal(int i){
double area=i*i*Math.PI;
double round=i*2*Math.PI;
System.out.println("圓周=" round);
System.out.println("面積=" area);
}
}
能幫我加註解跟解釋意思ㄇ
謝謝....
1 個解答
- 2 0 年前最佳解答
import java.io.*;
public class CalCir{
public static void main(String args[])throws IOException{
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
String str;//nothing, just create a String object....
int i=0;//initial integer i
System.out.println("請輸入圓半徑");
str=buf.readLine(); //讀入所輸入之數字
i=Integer.parseInt(str);
if(i>0){ //從1到i
TestCalCir tcc=new TestCalCir();
tcc.cal(i); //使用TestCalCir 計算周長及面積
}
else{
System.out.println("請輸入大於0的數字!");
}
}
}
class TestCalCir{
public void cal(int i){
double area=i*i*Math.PI; //算面積
double round=i*2*Math.PI; //算周長
System.out.println("圓周=" round); //印出面積
System.out.println("面積=" area); //印出周長
}
}
一共有兩個類別,
一個是TestCalCir:輸入半徑,計算周長及面積,並印出?
一個是CalCir,取得所輸入之數字i,從1到i,使用TestCalCir印出周長及面積。