Homework 11-28-2005
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Counter
{
private int count;
public Counter(int r)
{if(r<0)
{
System.out.println("error!");
r=0;}
else{
count=r;
}
}
public void countIncrease()
{
count=count+1;
}
public void countDecrease()
{
count=count-1;
}
public void show1()
{
System.out.println("count1:"+count);
}
public void show2()
{
System.out.println("count2:"+count);
}
}
public class ananfish2
{
public static void main(String args[])
{
Counter count1=new Counter(-4);
count1.show1();
Counter count2=new Counter(3);
count2.show2();
System.out.println("兩者皆增一比比看:");
count1.countIncrease();
count2.countIncrease();
count1.show1();
count2.show2();
System.out.println("一增一減比比看:");
count1.countIncrease();
count2.countDecrease();
count1.show1();
count2.show2();
if(count1 ==count2)
{System.out.println("count1 is equal to count2");
} else
{System.out.println("count1 does not equal to count2");
}
}
}
完成圖
0 Comments:
Post a Comment
<< Home