我正在研究一个基本上只显示我知道如何使用超类的小程序。除了我的布尔值之外,一切都很好。它应该要求使用他们想要注册的邮件列表。如果输入“yes”,布尔值应该为true,如果输入“no”,它应该是false。我的问题是,即使输入“no”,它仍会注册为“yes”,使布尔值为true。请帮忙? (我希望做的意义一些外表。)布尔值不会改变
import java.util.Scanner;
public class CustomerDemo
{
public static void main(String[] args)
{
String name;
String address;
String telephone;
int customerNumber;
String input;
boolean mail = false;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your name: ");
name = keyboard.nextLine();
System.out.print("Enter your address: ");
address = keyboard.nextLine();
System.out.print("Enter your phone number: ");
telephone = keyboard.nextLine();
System.out.print("Enter your customer number: ");
customerNumber = keyboard.nextInt();
keyboard.nextLine();
System.out.print("Do you want to be on the mailing list (Yes or No): ");
input = keyboard.nextLine();
if (input.equalsIgnoreCase("yes")) {
mail = true;
}
Customer cust = new Customer(name, address, telephone, customerNumber, mail);
System.out.println("Hello " + cust.getName() + "!");
System.out.println("You are customer " + cust.getCustomerNumber() + ".");
if(mail = false){
System.out.println("You are not on the mailing list. ");
}
else {
System.out.println("You are on the mailing list. ");
}
}
}
如果(邮件= FALSE)是一个错误的表达。它应该是(mail == false),在改变这个之后试试 – 2013-05-01 01:52:29