Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 布尔值赢得';不变_Java_Boolean - Fatal编程技术网

Java 布尔值赢得';不变

Java 布尔值赢得';不变,java,boolean,Java,Boolean,我正在开发一个小程序,它基本上只是显示我知道如何使用超类。除了我的布尔值外,其他一切都很好。它应该询问他们想注册邮件列表的用户。如果输入“是”,则布尔值应为真;如果输入“否”,则布尔值应为假。我的问题是,即使我输入“否”,它仍然注册为“是”,使布尔值为真。请帮忙?(我希望这看起来有点道理。) 你不是在做比较,你是在做作业 此if(mail=false)等同于if(false),因为false被分配回mail 如果(!mail)则改为执行此操作,这相当于如果(!true)(或者如果(mail==f

我正在开发一个小程序,它基本上只是显示我知道如何使用超类。除了我的布尔值外,其他一切都很好。它应该询问他们想注册邮件列表的用户。如果输入“是”,则布尔值应为真;如果输入“否”,则布尔值应为假。我的问题是,即使我输入“否”,它仍然注册为“是”,使布尔值为真。请帮忙?(我希望这看起来有点道理。)


你不是在做比较,你是在做作业

if(mail=false)
等同于
if(false)
,因为
false
被分配回
mail


如果(!mail)则改为执行此操作,这相当于如果(!true)(或者如果(mail==false)如果您确实非常想执行此操作)

阅读代码时没有任何错误。。错误是您尝试打印的位置。如果(mail=false)条件不正确,
。。如果(mail==false),它应该是
请看这一行
if(mail=false)这应该是(!mail)

if(mail=false)是一个错误的表达式。。它应该是(mail==false),请在更改后重试。非常感谢。很抱歉问这么简单的问题!很高兴能帮上忙:是谁干的。非常感谢。很抱歉问这么简单的问题!成功了。非常感谢。很抱歉问这么简单的问题!
 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. "); 
        }
    }
}