「用Java画桃子」如何画桃子

博主:adminadmin 2022-12-19 14:33:07 62

今天给各位分享用Java画桃子的知识,其中也会对如何画桃子进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用java程序写出来 猴子摘了一些桃子,第一天吃了一半,又多吃了一个,第二天又吃了一半,

                int tao=1;//第十天 1个

for (int i = 9; i 0; i--) {

tao=(tao+1)*2; 

}

System.out.println("一共摘了"+tao+"个桃子");

用java程序写一个猴子第一天摘下N个桃子,当时就吃了一

int count = 1;

for(int i=2;i=10;i++){

count=(count+1)*2;}

System.out.println("猴子第一天一共摘了"+count+"个桃子");

java程序题:定义一个抽象类-水果,其中包括getWeight()方法,编写程序分别创建苹果、

水果类

abstract public class Fruit {

abstract public double getWeight();

}

苹果类

public class Apple extends Fruit {

private double weight;

public Apple(double weight) {

this.weight = weight;

}

@Override

public double getWeight() {

return weight;

}

}

橘子类

public class Orange extends Fruit {

private double weight;

public Orange(double weight) {

this.weight = weight;

}

@Override

public double getWeight() {

return weight;

}

}

桃子类

public class Peach extends Fruit {

private double weight;

public Peach(double weight) {

this.weight = weight;

}

@Override

public double getWeight() {

return weight;

}

}

主类

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Fruit[] fruits = { new Peach(12), new Apple(2), new Orange(5) };

for (Fruit fruit : fruits) {

System.out.println(fruit.getClass().getName() + "的重量是"

+ fruit.getWeight());

}

}

}

运行结果

Peach的重量是 12.0

Apple的重量是 2.0

Orange的重量是 5.0

用Java画桃子的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于如何画桃子、用Java画桃子的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-19,除非注明,否则均为首码项目网原创文章,转载请注明出处。