这是我的代码:
import java.util.Scanner;
public class BankAccount1
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
char pickup;
char size;
char type;
String name;
double cost=0.0;
int i;
for (i=0; i<2; i++)
{
System.out.println("What is your name?");
name = input.nextLine();
System.out.println("size of pizza: ");
size = input.next().charAt(0);
System.out.println("type of pizza: ");
type = input.next().charAt(0);
System.out.println("pick up or delivery?");
pickup = input.next().charAt(0);
if(size == 'S' || type == 'V') {cost = 10.0;}
else if(size == 'M' || type == 'V') {cost = 12.25;}
else if(size == 'L' || type == 'V') {cost = 14.50;}
else if(size == 'S' || type == 'C') {cost = 7.0;}
else if(size == 'M' || type == 'C') {cost = 8.0;}
else if(size == 'L' || type == 'C') {cost = 9.0;}
if(pickup == 'D'){
cost=cost+1.50;
System.out.println("Name: "+name+". Your cost is: "+cost);}
else {
System.out.println("Name: "+name+". Your cost is: "+cost);}
}
}
}
我的代码中有一个 for 循环,它询问名称、大小、类型和拾取。第一次运行时,它要求输入所有字段,但第二次,名称字段由于某种原因不允许我输入姓名,它打印“你叫什么名字?” 但它不允许我输入名字......?有人能告诉我为什么吗?谢谢。
这就是它的样子:http: //i.stack.imgur.com/eb1BA.jpg