Calendar cal=Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR,10); String strDate=cal.get(Calendar.YEAR)+”年“ +(cal.get(Calendar.MONTH)+1)+”月“ +cal.get(Calendar.DATE)+”日“;
System.out.println(“10天后的日期为:“+strDate); } }
3、请定义一个交通工具(Vehicle)的类其中有: 属性速度(speed)体积(size)等等 方法移动(move())设置速度(setSpeed(int speed))加速speedUp(),减速speedDown()等等. 最后在测试类Vehicle中的main()中实例化一个交通工具对象并通过方法给它初始化speed,size的值并且通过打印出来。另外调用加速减速的方法对速度进行改变。
参考代码: public class Vehicle {
private int speed; private String size; public void move()
{
System.out.println(\}
public void setSpeed(int speed) { }
public void speedUp() { }
public void speedDown() {
Vehicle v=new Vehicle(); }
public static void main(String[] dsa) {
Vehicle v=new Vehicle(); v.speed=100; v.size=\v.setSpeed(20); Vehicle v=new Vehicle(); v.setSpeed(1000);
System.out.println(\
System.out.println(\initial speed is\my size is
\ }
v.speedUp(); v.speedDown(); }