import java.io.*;
public class TestFileInputStream {
public static void main(String[] args) {
FileInputStream in = null;
int b = 0;
try {
in = new FileInputStream("C:\\hello.txt");
while((b=in.read())!=-1) {
System.out.print((char)b);
}
}catch(IOException e) {
e.getMessage();
e.printStackTrace();
}
finally {
try {
in.close();
}catch(IOException e) {
e.getMessage();
e.printStackTrace();
}
}
}
}
(2)
public class Cylinder {
double radius,height;
public static void main(String[] args) {
Cylinder c = new Cylinder();
System.out.println("圓柱體體積:"+c.Volume(10, 5));
}
double Volume(double r,double h) {
return 3.14*r*r*h;
}
}
(3)
public class Paixu {
public static void main(String[] args) {
int [] myInt=new int[]{37,47,23, 5,19,56};
int t=0;//比較運算時交換中間數
final int len=myInt.length;
for(int i=0;i<len-1;i++){//控制所有數字都被比較循環
for(int j=0;j<len-i-1;j++){//控制每個數和數組裏面其他數壹壹比較
if(myInt[j]>myInt[j+1]){
t=myInt[j];
myInt[j]=myInt[j+1];
myInt[j+1]=t;
}
}
}
for(int r=0;r<len;r++){//控制輸出結果
System.out.println(myInt[r]);
}
}
}