永发信息网

JAVA编程类题目

答案:2  悬赏:60  手机版
解决时间 2021-12-22 03:50
  • 提问者网友:欲劫无渡
  • 2021-12-21 23:11
定义一个汽车类Car,包含以下私有数据库成员:车名name(字符串类型),类型type(字符型),颜色color(字符串类型)。一个有参构造函数设置car的信息,一个公开方法setColor()设置汽车的颜色,一个公开方法printCar()输出汽车的信息。在main函数中,先利用构造函数创建一个汽车对象car1(“宝马”,”轿车”,”白色”),再利用setColor()方法,将颜色变为红色。最后输出car1的信息。
最佳答案
  • 五星知识达人网友:渊鱼
  • 2021-12-21 23:29
package demo20;

class Car {

private String name;

private String type;

private String color;

public Car(String name, String type, String color) {
this.name = name;
this.type = type;
this.color = color;
}

public void setColor(String color) {
this.color = color;
}

public void printCar() {
System.out.println("名称:" + name + ", 类型:" + type + ", 颜色" + color);
}
}

public class App7 {

public static void main(String[] args) {

Car car1 = new Car("宝马", "轿车", "白色");
car1.printCar();
car1.setColor("红色");
car1.printCar();

}

}
全部回答
  • 1楼网友:污到你湿
  • 2021-12-22 00:03

我手里刚好有前两天写好的,但替换成的词不大一样,lz自己换下吧

public class flp {  public static void main( string args[] ) {   int i;

  for( i=1; i<=100; i++ ) {    if( ( i % 3 != 0 ) && ( i % 5 != 0 ) )     system.out.printf( "%8d", i );    else     if( i % 3 == 0 )     system.out.print( ( ( i % 5 != 0 ) ? "    flip" : "flip" ) );     if( i % 5 == 0 ) {     if( i % 3 != 0 )     system.out.print( "    " );     system.out.print( "flop" );     }   }  }

}

以下是运行时的截图,应该和lz的要求一样吧?

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯