用java编程 要有一个循环,两个函数 50行左右 ,简单易懂的吧
1个回答
展开全部
public class Cat{
private String name;
public Cat(String name){
this.name =name;
}
public void eat(int num){
System.out.println("Cat eat "+num+" fish");
}
pulic String like(){
System.out.println("Cat like capture mouse");
return "mouse";
}
public static void eatManyFishes(Cat cat,int fishNum){
for(int i=0;i<=fishNum;i++){
cat.eat(i);
}
}
public static void main(String[] x){
Cat cat = new Cat("caty");
eatManyFishes(=cat,10);
}
}
private String name;
public Cat(String name){
this.name =name;
}
public void eat(int num){
System.out.println("Cat eat "+num+" fish");
}
pulic String like(){
System.out.println("Cat like capture mouse");
return "mouse";
}
public static void eatManyFishes(Cat cat,int fishNum){
for(int i=0;i<=fishNum;i++){
cat.eat(i);
}
}
public static void main(String[] x){
Cat cat = new Cat("caty");
eatManyFishes(=cat,10);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询