十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
public class Test {
创新互联是一家集网站建设,曲松企业网站建设,曲松品牌网站建设,网站定制,曲松网站建设报价,网络营销,网络优化,曲松网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
public static void main(String [] args){
System.out.println("爬出井口需要的天数:"+getDays());
}
public static int getDays(){
int i = 0, initHeight = 0;
for(;initHeight 7 ;i++){
initHeight = initHeight+3;//白天
initHeight = initHeight-2;//晚上
//合并其实就是一天爬1米 initHeight = initHeight+1;
}
return i;
}
}
白天爬3米,晚上掉下2米,实际一天只爬了1米。具体代码如下:
public class Demo4 {
public static void main(String[] args) {
int distance = 0; // 所爬的路程
int days = 0; // 所用天数
while (distance 30) {
distance += 3; // 白天爬3米
distance -= 2; // 晚上滑下2米
days++;
}
System.out.println("爬出井用了" + days + "天");
}
}
接口和类全在一个包下,如果不在一个包下记得import调用,show的重写你根据需要自己改
//ShouFei 接口
public interface ShouFei {
public void fuFei(double mileage);
public void show();
}
//Bus类
public class Bus implements ShouFei{
String airConditioning;
double money;
public Bus(String airConditioning){
this.airConditioning = airConditioning;
}
@Override
public void fuFei(double mileage) {
if(airConditioning.equals("空调")){
money = 2;
}else{
money = 1;
}
}
@Override
public void show() {
System.out.println("公交车,"+airConditioning+",费用:"+money);
}
}
//Taxi类
public class Taxi implements ShouFei{
double mileage;
boolean isDay;
double money;
public Taxi(boolean isDay){
this.isDay = isDay;
}
@Override
public void fuFei(double mileage) {
this.mileage = mileage;
//判断是否为白天
if(isDay){
//判断里程数是否大于三公里
if(mileage3){
money=8;
}else{
money = 8 + (mileage-3)*1.5;
}
}else{
if(mileage3){
money=10;
}else{
money = 10 + (mileage-3)*1.5;
}
}
}
@Override
public void show() {
System.out.print("出租车,");
if(isDay){
System.out.print("白天");
}else{
System.out.print("晚上");
}
System.out.println(",里程数:"+mileage+"收费:"+money);
}
}
//测试类
public class Test {
public static void main(String[] args) {
Bus bus = new Bus("空调");
bus.fuFei(10);
bus.show();
Taxi taxi = new Taxi(true);
taxi.fuFei(20);
taxi.show();
}
}