问答详情
源自:12-1 综合练习

6-1项目问题,为什么最后可载人,可载货没有输出

package zuche;

import java.util.Scanner;

public class Text {

public static int money=0;

public static int person=0;

public static int burden=0;

public static String[] r;

public static String[] h;

public static int j=0;

public static int k=0;

public static void main(String[] args) {

Scanner scan=new Scanner(System.in);

           ab ab=new ab();

        System.out.println("是否进入租车系统 1:是;0:否");

           int x=scan.nextInt();

           if(ab.ab(x)==1){

Car[] car={new a(),new b(),new c(),new d(),new e(),new f()};

System.out.println("输入你租车的数量");

int num=scan.nextInt();

System.out.println("输入你要租用的天数");

int day=scan.nextInt();

for(int i=0;i<num;i++){

System.out.print("输入你第"+(i+1)+"辆所选的车");

String ch=scan.next();

if(ch=="a"){

r[j]="奥迪A4";

j++;

}

if(ch=="b"){

r[j]="马自达6";

j++;

}

if(ch=="c"){

r[j]="皮卡雪6";

        h[k]="皮卡雪6";

j++;

k++;

}

if(ch=="d"){

r[j]="金龙";

j++;

}

if(ch=="e"){

h[k]="松花江";

k++;

}

if(ch=="f"){

h[k]="依维柯";

k++;

}

switch (ch){

case "a":money=money+500*day;

        person+=4;

        break;

case "b":money=money+400*day;

    person+=4;


    break;

case "c":money=money+450*day;

    person+=4;

    burden+=2;


    break;

case "d":money=money+800*day;

    person+=20;


    break;

case "e":money=money+400*day;

    burden+=4;


    break;

case "f":money=money+1000*day;

    burden+=20;


    break;

}

}

System.out.println("可载人的车有");

for(int j1=0;j1<j;j1++){

System.out.println(r[j1]);

}

System.out.println("可载货的车有");

for(int k1=0;k1<k;k1++){

System.out.println("h[k1]");

}

System.out.println("总载人"+person+"总载货"+burden);

System.out.println("总价格为"+money);




}

scan.close();

}

}

http://img.mukewang.com/5897f53c000104c801210107.jpg

提问者:慕粉4401746 2017-02-06 12:02

个回答

  • ziom
    2017-02-06 13:06:49
    已采纳

    代码没有格式化,不好看,把项目打包发给我吧,我抽空帮你看看,1808570357@qq.com