2013年5月21日 星期二

package封裝實例

建立Circle.java和Square.java以及同目錄的Test資料夾
Circle.java
package Test;
public class Circle {
        double radius;

        public Circle(double r){
       radius=r;
 }

 public double area(){
                      return radius*radius*Math.PI;
 }

 public double perimeter(){
                      return radius*2*Math.PI;
 }
}
Square.java
package Test;
public class Square {
        double size;

        public Square(double s){
       size=s;
 }

 public double area(){
                      return size*size;
 }

 public double perimeter(){
                      return size*4;
 }
}
輸入指令 javac -d /Test Circle.java
輸入指令 javac -d /Test Square.java
將資料封裝在/Test/Test裡面並建立main.java在/Test裡(封裝資料夾外) 即可讀取
class main{
 static public void main(String argv[]){
  Test.Circle c = new Test.Circle(5.6);    // generate a Circle object
                Test.Square s = new Test.Square(7.3);    // generate a Square object

                                // Output Circle's  area & perimeter (raduis is 5.6)
  System.out.println("Circle's area: "+c.area());
  System.out.println("Circle's perimeter: "+c.perimeter());
                                // Output Square's  area & perimeter (size is 7.3)
  System.out.println("Square's area: "+s.area());
  System.out.println("Square's perimeter: "+s.perimeter());
                }
}

物件導向實例

以物件導向讀取student.class 實作test.java
class test {
 public static void main(String[] args){
  student std = new student();
  System.out.println("Name :"+std.getName());
  System.out.println("Age :"+std.getAge());
  System.out.println("Gender :"+std.getGen());

 }
}

物件導向設計原理期末考(I)


1. 將兩班成績分數透過切割函數,切割成小字串,整數字串轉成整數且存於整數陣列,
(a) 將整數陣列當作score建構方法參數,且產生一score物件。
(b) 再透過score物的成員方法完成題目的要求。
   class score包括:
一個資料成員:
int[] data;
  一個建構方法:
score(int[] dd)    // 設定int[] data初始值
兩個成員方法:
getLevelNum( base)     // 傳回整數 base (含)分數以上人數
getPassAvg() // 傳回及格成績的平均分數(小數後兩位)



class score{
 int[] data;

 score(int[] dd){
  data=dd;
 }
 int getLevelNum(int base){
  int num=0;

  for(int kk:data) 
   if(kk >= base) num++;
  return num;
 }

 double getPassAvg(){
  int sum=0, num=0;
  
  num=getLevelNum(60);
  for(int i:data) {
   if(i>=60) sum+=i; 
  }
  return (int)((double)sum/num*100)/100.0;
 }
}

class prob10507{
        public static void main(String[] args){

 String IMDA="IMDA,75,88,62,77,69,82,79,85,93,44,81,53,66,71";
 String IMDB="IMDB/55/68/72/57/83/77/93/75/66/85/83/47/52/87/96/53/62/89/76/51";
 int gradeA, gradeB, gradeC, gradeD,gradeF; 

        String[] token=IMDA.split("[,]");
 int[] data=new int[token.length-1];

 for(int i=1;i<token.length;i++)
  data[i-1]=Integer.parseInt(token[i]);

 score cls1=new score(data);
                gradeA=cls1.getLevelNum(90);
                gradeB=cls1.getLevelNum(80)-cls1.getLevelNum(90);
                gradeC=cls1.getLevelNum(70)-cls1.getLevelNum(80);
                gradeD=cls1.getLevelNum(60)-cls1.getLevelNum(70);
                gradeF=cls1.getLevelNum(0)-cls1.getLevelNum(60);
 System.out.println(" CLS Name: "+ token[0]);
 System.out.println("     Numbers of students: "+ (token.length-1));
 System.out.println("     Pass Average Number: "+cls1.getPassAvg());
 System.out.println("     grade A Number: "+gradeA);    // score >= 90
 System.out.println("     grade B Number: "+gradeB);    // score >= 80 and score < 90
 System.out.println("     grade C Number: "+gradeC);    // score >= 70 and score < 80
 System.out.println("     grade D Number: "+gradeD);   // score >= 60 and score < 70
 System.out.println("     grade F Number: "+gradeF);    // score < 60

        String[] token2=IMDB.split("[/]");
 int[] data2=new int[token2.length-1];

 for(int i=1;i<token2.length;i++)
  data2[i-1]=Integer.parseInt(token2[i]);

 score cls2=new score(data2);
                gradeA=cls2.getLevelNum(90);
                gradeB=cls2.getLevelNum(80)-cls2.getLevelNum(90);
                gradeC=cls2.getLevelNum(70)-cls2.getLevelNum(80);
                gradeD=cls2.getLevelNum(60)-cls2.getLevelNum(70);
                gradeF=cls2.getLevelNum(0)-cls2.getLevelNum(60);
 System.out.println(" CLS Name: "+ token2[0]);
 System.out.println("     Numbers of students: "+ (token2.length-1));
 System.out.println("     Pass Average Number: "+cls2.getPassAvg());
 System.out.println("     grade A Number: "+gradeA);
 System.out.println("     grade B Number: "+gradeB);
 System.out.println("     grade C Number: "+gradeC);
 System.out.println("     grade D Number: "+gradeD);
 System.out.println("     grade F Number: "+gradeF);
        }
}



2. (a) class degree 包括:
  一個建構方法:
degree( char, double)    // 設定degreeC, degreeF 初始值
兩個資料成員:
private: double degreeC, degreeF;
  四個成員方法:
private:  CtoF()    // degreeC  degreeF
private:  FtoC()    // degreeF  degreeC
public: getDegC()    // 傳回degreeC
public: getDegF()    // 傳回degreeF
(b) class check 繼承degree
  一個建構方法:
check(char, double)  //呼叫父類別之建構方法,設定degreeC, degreeF 初始值
有兩個成員方法:
public:  degChk()          // 傳回體溫狀態代碼(整數)
public:  toStatus(byte)    // 傳回體溫狀態(字串)
(c) 透過相關的成員方法完成題目要求(產業輸出內容)。

體溫、代碼與狀態對照表
~ 36.4c (97.5f)     -1 (Hypothermia) (體溫過低)
36.4c (97.5f) ~ 37.8c (100f)   0 (Normal) (正常)
37.8c (100.f) ~ 39.4c (103.0f)   1 (Fever) (發燒)
39.4c (103.0f) ~ 40.3c (104.5f)   2 (High Fever) (高燒)
40.3c (104.5f) ~               3 (Serious) (嚴重)



class degree{
 private double degC=0, degF=32;

 degree(char CF, double dd){
  if(CF=='C'){
   degC=dd;
   CtoF();
  }else if(CF=='F'){
   degF=dd;
   FtoC();
  }
 }
 private void CtoF(){
  degF=degC*5.0/9.0+32;
 }
 private void FtoC(){
  degC=(degF-32)/9.0*5.0;
 }
 double getDegC(){
  return degC;
 }
 double getDegF(){
  return degF;
 }
}

class check extends degree{
 check(char cc, double dd){
  super(cc,dd);
 }
  
 byte degChk(){               // if-else statement 
                double degC=getDegC();            // call getDegC to get degC
  if(degC < 36.4) return -1;
                else if(degC < 37.8) return 0;
                else if(degC < 39.4) return 1;
                else if(degC < 40.3) return 2;
                else return 3;

 }
 String toStatus(byte n){     // switch case statement
  switch(n){
  case -1:
   return "Hypothermia";
  case 0:
   return "Normal";
  case 1:
   return "Fever";
  case 2:
   return "High Fever";
  default:
   return "Serious";
  }
 } 
}
 
class prob20507{
        public static void main(String[] args){

  check c1 =new check('C',38.3);

 System.out.println(" degree C "+c1.getDegF());
 System.out.println(" degree F "+c1.getDegC());
 System.out.println("   Status code: "+ c1.degChk());
 System.out.println("   Degree Status: "+c1.toStatus(c1.degChk()));

 check c2 = new check('F',103.5);
 System.out.println(" degree C "+c2.getDegF());
 System.out.println(" degree F "+c2.getDegC());
 System.out.println("   Status code: "+ c2.degChk());
 System.out.println("   Degree Status: "+c2.toStatus(c2.degChk())); 
        }
}

第22次ITSA答案參考

題目連結: https://db.tt/tg3FeNrb (右鍵開新視窗)
1
#include<stdio.h>
void minheap(int *n[1000],int size){
int i;
while(1){
    int flag=1;
    for(i=1;i<=size;i++){
        if(n[i]>n[i*2+1]){int t; t=n[i],n[i]=n[i*2+1],n[i*2+1]=t; flag=0;}
        if(n[i]>n[i*2]){int t; t=n[i],n[i]=n[i*2],n[i*2]=t; flag=0;}
    }
    if(flag) break;
}

}

int main(){
int n[1000],size=0,num,i;
for(i=0;i<1000;i++) n[i]=500;
char order;
while(scanf("%c",&order)!=EOF){
    if(order=='a'){
        scanf("%d",&num);
        n[++size]=num;
        minheap(n,size);
        printf("The min-heap is of size %d and the current minimum is %d a\n",size,n[1]);
    }else if(order=='b'){
        n[1]=n[size];
        n[size]=500;
        --size;
        minheap(n,size);
        printf("The min-heap is of size %d and the current minimum is %d b\n",size,n[1]);
    }else if(order=='c'){
        for(i=1;i<=size;i++) {
            if(i!=1) printf(" ");
            printf("%d",n[i]);
        }
    }else if(order=='d'){
        break;
    }
}

return 0;
}

2
#include<stdio.h>
int n[90000],top=0,min=1e9;
int search(int s,int sum){
int ns,nsum,i;
if(s==top-1||s==top-2) { /* printf("*%d\n",sum)*/; if(sum<=min) min=sum; return 0;}

for(i=1;i<=3;i++){
    if((s+i)<top){
        //printf("i=%d s=%d sum=%d\n",i,s,sum);
        ns=s+i,nsum=sum+n[s+i];
        //printf("          n s=%d sum=%d,top=%d\n",ns,nsum,top);
        search(ns,nsum);

    }
}
    return 0;
}

int main(){
    int tmp;
    while(scanf("%d",&tmp)&&tmp) n[top++]=tmp;
    //while(scanf("%d",&tmp)!=EOF) n[top++]=tmp;
    search(0,n[0]);
    search(1,n[1]);
    printf("%d\n",min);
    return 0;
}

3
#include<stdio.h>
#include<string.h>
int n,map[5000][5000]={0},time[5000]={0},top=0;
int max=0;
void search(int mask,int sum,int size){
    if(size>=top) return;
    if(sum>max) max=sum;
    //printf("mask=%d sum %d size %d\n",mask,sum,size);
    int i,j;
    int max=0;
    for(i=0;i<top;i++){
        int ch=-1,max=0;
        for(j=0;j<top;j++){
            if(map[i][j]!=0&&(mask&(1<<j))&&(mask&(1<<i))){
                if(time[j]>max) max=time[j],ch=j;
            }
        }
        if(ch!=-1){
            mask-=1<<i;
            mask-=1<<ch;
            //printf(" (%d,%d) ",i,ch);
            search(mask,time[ch]+time[i],++size);
        }
    }




    return ;
}

void task (char t[100]){
    //printf("task\n");
    int c=0,tt=0,tn=0;
    while(t[++c]!=','){
        tt*=10;
        tt+=t[c]-'0';
    }

    while(t[++c]){
        tn*=10;
        tn+=t[c]-'0';
    }

    time[tt-1]=tn;
    top++;
    //printf("**task=%d time=%d\n",tt,time);

}

void prec (char p[100]){
    //printf("prec\n");
    int c=0,tb=0,ta=0;
    while(p[++c]!=','){
        tb*=10;
        tb+=p[c]-'0';
    }
    c++;
    while(p[++c]){
        ta*=10;
        ta+=p[c]-'0';
    }

    map[ta-1][tb-1]=1;
    //printf("  pp %d %d\n",tb,ta);
}

int main(){
    char input[100];
    int i,j;

    while(gets(input)){
        if(strcmp(input,"end")==0) break;
        char left[100],right[100]={0};
        int n1=0,n2=0;
        while(input[n1]!=':') left[n1]=input[n1],n1++;
        left[n1++]='\0';
        while(input[n1]) right[n2++]=input[n1++];
        right[n2]='\0';

        if(strcmp(left,"Process")==0){
            int sum=0,n3=0;
            while(right[n3]) sum*=10,sum+=right[n3++]-'0';
            n=sum;
            //printf("sum=%d\n",sum);
        }else if(strcmp(left,"Task")==0){
            task(right);
        }else if(strcmp(left,"Prec")==0){
            prec(right);
        }
    }

    /*for(i=0;i<top;i++) printf("%d ",time[i]);
    printf("  top=%d\n",top);

    for(i=0;i<top;i++){
        for(j=0;j<top;j++)
            printf("%d ",map[i][j]);
        puts("");
    }*/

    int mask=~(~0<<top);
    search(mask,0,0);
    printf("%d\n",max);
    return 0;
}

4
#include<stdio.h>
char ans[100][100];
int top=0;
int map[100][100],n,min=1e9;
int star,end;

int search(int a[n],int p,int size,int mask){
    int i,c;
    mask|=1<<p;
    a[size++]=p;

    if(size>=n) return 1;
/*
printf("p=%d size=%d mark=%d\n",p,size+1,mask);
for(i=0;i<size;i++) printf("%d ",a[i]);
puts("");*/
    if(p==end) {
        if(size<min){
            min=size;
            top=0;
            c=0;
            for(i=0;i<size;i++){
                if(i!=0) ans[top][c++]=',';
                ans[top][c++]=a[i]+'0';
            }
            ans[top++][c]='\0';
        }else if(size==min){
            c=0;
            for(i=0;i<size;i++){
                if(i!=0) ans[top][c++]=',';
                ans[top][c++]=a[i]+'0';
            }
            ans[top++][c]='\0';
        }
            /*printf("ans min=%d ",min);
            for(i=0;i<size;i++) printf("%d ",a[i]);
            puts("");*/

        return 0;
    }

    for(i=0;i<n;i++){
        if(map[p][i]==1&&(mask&(1<<i))==0)
            search(a,i,size,mask);
    }

}


int main(){
    scanf("%d,%d,%d",&n,&star,&end);
    int i,j;

    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            scanf("%d",&map[i][j]);

    int a[n];
    search(a,star,0,0);

    for(i=0;i<top;i++)
        printf("%s\n",ans[i]);

    return 0;
}

5
#include<stdio.h>
int main(){
while(1){
int n[100],top=0,num;
while(scanf("%d",&num)==1){
if(num==-999999) break;
n[top++]=num;
}
int i,j,max=n[0];
for(i=0;i<top;i++){
    int r=n[i];
    for(j=i+1;j<top;j++){
        r*=n[j];
        if(r>=max) max=r;
    }
}
printf("%d\n",max);
}
return 0;
}

第21次ITSA答案參考

題目連結:http://db.tt/dbfYqNFW (右鍵開新視窗)
1
#include<stdio.h>
int main(){
int n,sum=0,i,v=0,tmp;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&tmp);
    if(tmp>=v) v=tmp;
    else {
        sum+=v-tmp;
    }
}
printf("%d\n",sum);
return 0;
}

2
#include<stdio.h>
int main(){
int m,n,k;
scanf("%d",&m);
while(m--){
    scanf("%d %d",&n,&k);
    int mark[n],i;
    for(i=0;i<n;i++) mark[i]=1;
    int sum=n-1,p=0,tmp=k;
    while(sum){
        if(mark[p]==1){

            p++;
            if(p>=n) p-=n;

            tmp--;
        }
        else{

            p++;
            if(p>=n) p-=n;

        }
        if(tmp==0){
            if(p-1>=0)
            mark[p-1]=0;
            else mark[p-1+n]=0;
            sum--;
            tmp=k;
        }

    }
    int ans;
    for(i=0;i<n;i++) if(mark[i]!=0) ans=i;
    char name[50];
    for(i=0;i<n;i++){
        scanf("%s",name);
        if(i==ans) printf("%s\n",name);
    }

}
return 0;
}

3
#include<stdio.h>
int main(){
int x1=0,b1,b2;
char input[100];
scanf("%s",input);
scanf("%d",&b1);
scanf("%d",&b2);
int i,flag=0,no;
for(i=0;input[i];i++){
    if(input[i]>='0'&&input[i]<='9') no=input[i]-'0';
    else if(input[i]>='A'&&input[i]<='F') no=input[i]-'A'+10;
    if(no>=b1) flag=1;
    x1*=b1;
    x1+=no;
}

char ans[100];
int n=0;
while(x1){
if(x1%b2>=10) ans[n]=x1%b2-10+'A';
else ans[n]=x1%b2+'0';
n++;
x1/=b2;
}

for(i=n-1;i>=0;i--) printf("%c",ans[i]);
puts("");

return 0;
}

4
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int top=1;
while(n-->1) top*=10;
int i;
for(i=1;i<top;i++){
    int t=i,sum=0,p=1;
    while(t){
    int tmp=t%10;
    t/=10;
    sum+=tmp;
    p*=tmp;
    }
    if(sum==p) printf("%d\n",i);
}
puts("");
return 0;
}

5
#include<stdio.h>
#include<math.h>
double dist (double x,double y,double a,double b){
return sqrt((x-a)*(x-a)+(y-b)*(y-b));
}

int main(){
int n;
int  x[100],y[100];
scanf("%d",&n);
int i,j;
double min=1e9;
for(i=0;i<n;i++) scanf("%d %d",&x[i],&y[i]);



for(i=0;i<n;i++)
    for(j=i+1;j<n;j++){
        //printf("(%d,%d)-(%d,%d) %f\n",x[i],y[i],x[j],y[j],dist(x[i],y[i],x[j],y[j]));
        if(dist(x[i],y[i],x[j],y[j])<=min&&i!=j) min=dist(x[i],y[i],x[j],y[j]);
    }

printf("%.4f\n",min);


return 0;
}

2013年4月13日 星期六

物件導向期中考-所有小考程式詳解

ex0226a
class ex0226a{
	public static void main(String[] args)
	{
		String fName="John", lName="Chen";
		int weight=56;               // weight: Kg
		int height=175;              // height: cm
		int age=20;
		boolean gender=true;

		// 1cm = 0.0328 英呎
		// 1kg  = 2.21 磅

		System.out.println(" Name: "+fName+" "+ lName);
		System.out.println(" Gender: "+gen(gender));
		System.out.println(" weight: "+wei(weight)+" 磅 ");
		System.out.println(" height: "+hei(height)+" 英呎 ");
	}
	public static String gen(boolean gen)
	{
        if(gen=true) return "Man";
        else return "Female";
	}
	public static Double wei(int wei)
	{
        return wei*2.21;
	}
	public static Double hei(int hei)
	{
        return hei*0.0328;
	}



}

ex0305a
import java.io.*;

class ex0305a{
	public static void main(String[] args) throws IOException{
//
//              input a string & transfer into a integer
//   
                System.out.print(" Input a number :");
	BufferedReader br =new 
		BufferedReader(new InputStreamReader(System.in));
	String str=br.readLine();
	int fee=Integer.parseInt(str);
//
                System.out.println(" NT1000 :" +fee/1000 );
		fee%=1000;
                System.out.println(" NT500 :" + fee/500);
		fee%=500;
                System.out.println(" NT100 :" + fee/100);
		fee%=100;
                System.out.println(" NT50 :" + fee/50);
		fee%=50;
                System.out.println(" NT10 :" + fee/10);
		fee%=10;
                System.out.println(" NT5 :" + fee/5);
		fee%=5;
                System.out.println(" NT1 :" + fee/1);

	}
}
ex0312a
class ex0312a{
        public static void main(String[] args){
	int data[]={81,95,66,80,77,51,69,33,-1,46,90,87,93,72,63,55,-1,65,66,71,50,88,47,49,83,61};

//       
//     Statistic A, B, C, D, Fail & absent students number
//
//    Accumulate total score and total number (except absent students)
//
	int na=0,nb=0,nc=0,nd=0,fn=0,an=0,sum=0;
	for(int i:data){
		if(i>=0){
			sum+=i;
			if(i>=90) na++;
			else if(i>=80) nb++;
			else if(i>=70) nc++;
			else if(i>=60) nd++;
			else fn++;

		}
		else
		an++;
	}

		System.out.println(" Number of A :"+na);
		System.out.println(" Number of B :"+nb);
		System.out.println(" Number of C :"+nc);
		System.out.println(" Number of D :"+nd);
		System.out.println(" Fail Number :"+fn);
		System.out.println(" Absent Number  :"+ an);
		System.out.println(" *** Average :"+avg(sum,data.length-an));
        }
//
// sum: total score (except absent students)
//
// num: total number (except absent students)
//
	public static double avg(int sum, int num){
		double tmp;
		int tmp1;

		tmp=(double)sum/num;
		tmp1=(int)(tmp*10);
		return tmp1/10.0;
	}
}

ex0319b
class ex0319b{
	public static void main(String[] args) 
	{
		int[][] matA={{1,2,3},{4,5,6},{7,8,9}};
		int[][] matB={{1,7,6,4,3},{2,1,5,7,9},{4,3,5,1,7}};
		int[][] matC=new int[3][5];
		// Declate and allocate two dimension int array ==> matC
		int sum=0;

                                  mtrPtr(matA);
		System.out.println("=====================================");
                                  mtrPtr(matB);
                for(int i=0;i<matC.length;i++){
			for(int j=0;j<matC[i].length;j++){
				sum=0;
				for(int k=0;k<matC.length;k++)
					sum=sum+matA[i][k]*matB[k][j];
				matC[i][j]=sum;
			}
		}
		System.out.println("=====================================");
                                  mtrPtr(matC);
	}
	public static void mtrPtr(int[][] mat){
        for(int i=0;i<mat.length;i++){
			for(int j=0;j<mat[i].length;j++)
				System.out.print("  "+mat[i][j]+"\t");
			System.out.println();
		}
	}
}

ex0326b
class student{
	String name;
	int age;
	boolean gender;

	student(){};
	void setName(String nn){
		name=nn;
	}
	String getName(){
		return name;
	}

	void setAge(int nn){
		age=nn;
	}
	int getAge(){
		return age;
	}

	void setGender(boolean nn){
		gender=nn;
	}
	boolean getGender(){
		return gender;
	}
}

class ex0326b{
	public static void main(String[] args) 
	{
		student std01=new student();
		std01.setName("Mary Chen");
		std01.setAge(20);
		std01.setGender(true);
		System.out.println(" Std name: "+std01.getName());
		System.out.println(" Std age: "+std01.getAge());
		System.out.println(" Std gender: "+std01.getGender());
	}
}

ex0326d
class score{
	int[] data;
	int base=60;

	score(int[] dd){ data=dd;}
	int getHigh(){
        	int high=0;
		for(int i:data) if(i>high) high=i;
		return high;
	}
	int passNo(){
		int count=0;
		for(int i:data) if(i>=base) count++;
		return count;
	}
	float getAvg(){
		float sum=0f;
		for(int i:data) sum+=i;
		return sum/(float) data.length;
	}
}

class ex0326d{
	public static void main(String[] args) 
	{
		int[] dataA={99,88,77,66,55,44,92,56};
		int[] dataB={63,57,89,73,61,72,78,47,76,85,63,90,51,68,39};
		int[] dataC={79,78,47,96,85,54,80,66,73,52,84,73,97,60,55,70,65};
		score itmA=new score(dataA);
		score itmB=new score(dataB);
		score itmC=new score(dataC);

		System.out.println(" Highest score of itmA: "+itmA.getHigh());
		System.out.println(" Pass No of itmA: "+itmA.passNo());
		System.out.println(" Average of itmA: "+itmA.getAvg());
		System.out.println(" Highest score of itmB: "+itmB.getHigh());
		System.out.println(" Pass No of itmB: "+itmB.passNo());
		System.out.println(" Average of itmB: "+itmB.getAvg());
		System.out.println(" Highest score of itmC: "+itmC.getHigh());
		System.out.println(" Pass No of itmC: "+itmC.passNo());
		System.out.println(" Average of itmC: "+itmC.getAvg());
		System.out.println(" *Highest score of all: "+getMax(itmA.getHigh(),itmB.getHigh(),itmC.getHigh()));
		System.out.println(" *Pass No of all: "+(itmA.passNo()+itmB.passNo()+itmC.passNo()));
		System.out.println(" *Average of all: "+(itmA.getAvg()+itmB.getAvg()+itmC.getAvg())/3);
	}
	public static int getMax(int a, int b, int c){
		if(a > b)
			if( a > c) return a;
			else return c;
		else
			if(b > c) return b;
			else return c;
	}
}

ex0326x
class ex0326x{
	public static void main(String[] args) 
	{
		int[][] fee={{45,40,50,30,45},{100,95,80,90,110},
                                                     {90,85,120,110,150}};
		int[] sumDay=new int[5];
		int[] sumBld=new int[3];
		int sum=0;

		for(int i=0;i<3;i++){
			sum=0;
			for(int j=0;j<5;j++){
				sum=sum+fee[i][j];
			}
			sumBld[i]=sum;
		}
		for(int j=0;j<5;j++){
			sum=0;
			for(int i=0;i<3;i++){
				sum=sum+fee[i][j];
			}
			sumDay[j]=sum;
		}	
                                  mtrPtr(fee);
		System.out.println("  Total fee of Breakfast, Lunch and dinner: "+
                                                             sumBld[0]+"  "+sumBld[1]+"  "+sumBld[2]);
		System.out.print("  Total fee of each day: ");
		for(int df: sumDay) System.out.print("  "+df);
		System.out.println();
	}
	public static void mtrPtr(int[][] mat){
                                  for(int i=0;i<mat.length;i++){
			for(int j=0;j<mat[0].length;j++)
				System.out.print("  "+mat[i][j]+"\t");
			System.out.println();
		}
	}
}

ex0409b
class point{
	int x, y;

	point(){ 
		x=0;
		y=0;
	}
	
	point(int x, int y){
		this.x=x;
		this.y=y;
	}

	double distance(){   // Distance from point to origin 
		return (int) (Math.sqrt(x*x+y*y)*100)/100.0;	
	}
	int location(){
		if(x==0 && y==0) return 0;       // on origin
		if(x>0 && y>0) return 1;           // on 1st quadrant
		if(x<0 && y>0)  return 2;          // on 2nd quadrant
		if(x<0 && y<0)  return 3;          // on 3rd quadrant
		if(x>0 && y<0) return 4;           // on 4thquadrant
		if(y==0) return 5;                     // on X axle
		return 6;                                  // on Y axle
	}
	int disX(){     // Distance from point to X axle 
		return Math.abs(y);	
	}
	int disY(){    // Distance from point to Y axle
		return Math.abs(x);	
	}
}

class ex0409b{
	public static void main(String[] args) 
	{
		// create 3 points object;
                               // point1 ==> (0, 0), point2 ==> (4, 7), point3 ==> (-5 ,3)

		point p1 = new point();
		point p2 = new point(4,7);
		point p3 = new point(-5,3);

		System.out.println(" Location of point1: "+p1.location());
		System.out.println(" Location of ponit2: "+p2.location() );
		System.out.println(" Location of point3: "+p3.location() );

		System.out.println(" Distance of point1: "+p1.distance() );
		System.out.println(" Distance of point2: "+p2.distance() );
		System.out.println(" Distance of point3: "+p3.distance() );

		System.out.println(" Distance point2 to X : "+p2.disX() );
		System.out.println(" Distance point2 to Y : "+p2.disY() );
		System.out.println(" Distance point3 to X : "+p3.disX() );
		System.out.println(" Distance point3 to Y : "+p3.disY() );
	}
}

test1
class test1{
	public static void main(String[] args) 
	{
		int aa=-1,bb,cc,dd;

		bb=aa>>1;
		cc=aa>>>1;
		dd=aa<<1;
		System.out.println("   aa >> 1 "+ bb);
		System.out.println("   aa >>> 1 "+ cc);
		System.out.println("   aa << 1 "+ dd);
	}
}

2013年3月1日 星期五

Ma apologizes for 228



President Ma Ying-jeou apologized on behalf of the nation for the 228
Massacre yesterday, on the 66th anniversary of the tragic event.

Ma pledged at the ceremony that his administration will uphold rule of law,
protect human rights and promote cross-strait peace to prevent such a tragedy
from ever happening again.

Historians estimate that between 10-thousand and 30-thousand Taiwanese people
- many of them intellectuals - were killed by the Kuomintang in the brutal
crackdown on anti-government uprisings that began on February 28th, 1947,
shortly after the end of Japanese colonial rule.

The incident marked the beginning of the Kuomintang's White Terror period in
Taiwan, in which thousands more inhabitants vanished, died, or were
imprisoned.

馬道歉228
馬英九總統道歉,代表國家的228
大屠殺昨天,第66週年悲慘事件。

馬在儀式上承諾,他的政府堅持法治,
保護人權和促進兩岸和平,防止這樣的悲劇
再次發生。

歷史學家估計,在10萬和30萬台灣人
- 他們許多的知識分子 - 國民黨在殘酷的殺害
鎮壓反政府起義,於1947年2月28日開始,
日本殖民統治結束後不久。

該事件標誌著國民黨的白色恐怖時期
台灣,數千居民消失了,死了,或
監禁