为什么switch循环中的不会有指针报错,而后面for循环中会有指针报错?????
求解
package com.java;
import java.util.Scanner;
import javax.xml.validation.SchemaFactoryConfigurationError;
public class Mane {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
Scanner scanner=new Scanner(System.in);
int respond=scanner.nextInt();
if(respond==1)
{
System.out.println("您可租车的类型及其价目表:");
System.out.println("序号 汽车名称 租金 容量" );
System.out.println("1. 奥迪A4 500元/天 载人:4人");
System.out.println("2. 马自达6 400元/天 载人:4人");
System.out.println("3. 皮雪卡6 450元/天 载人:4人 载货:2吨");
System.out.println("4. 金龙 800元/天 载人:20人");
System.out.println("5. 松花江 400元/天 载货:4吨");
System.out.println("6. 依维柯 1000元/天 载货:20吨");
System.out.println("请输入您要租汽车的数量:");
int number=scanner.nextInt();
Car []car=new Car[6];
int total=0;
for(int i=0;i<number;i++)
{
System.out.println("请输入第"+(i+1)+"辆车的序号:");
int carNumber=scanner.nextInt();
switch (carNumber) {
case 1:
car[i]=new AodiA4();
total=car[i].cost+total;
break;
case 2:
car[i]=new Mazida6();
total=car[i].cost+total;
break;
case 3:
car[i]=new Pixueka6();
total=car[i].cost+total;
break;
case 4:
car[i]=new Jinlong();
total=car[i].cost+total;
break;
case 5:
car[i]=new Songhuajiang();
total=car[i].cost+total;
break;
case 6:
car[i]=new Yiweike();
total=car[i].cost+total;
break;
default:
break;
}
}
int totalCost=0;
System.out.println("请输入租车天数:");
int days=scanner.nextInt();
System.out.println(total*days);
for(int i=0;i<car.length;i++)
{
System.out.println(car[i].cost);
}
}
else
{
}
}
}怳然如夢
相关分类