我正在研究一個基本上只顯示我知道如何使用超類的小程序。除了我的布爾值之外,一切都很好。它應該要求使用他們想要註冊的郵件列表。如果輸入「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