gpt4 book ai didi

java - 试图让值相等

转载 作者:行者123 更新时间:2023-11-30 07:49:08 25 4
gpt4 key购买 nike

import java.util.Random;
import java.util.Scanner;
public class javascript {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random rand = new Random();

int door1 = 0;
int door2 = 0;
int door3 = 0;
int gdoor1 = 0;
int gdoor2 = 0;
int gdoor3 = 0;
int cdoor = 0;
door1 = rand.nextInt(3)+1;
door2 = rand.nextInt(3)+1;
door3 = rand.nextInt(3)+1;

if (door1 == door2 || door1 == door3){
door1 = rand.nextInt(3)+1;
}
if (door2 == door1 || door2 == door3){
door2 = rand.nextInt(3)+1;
}
if (door3 == door1 || door3 == door2){
door3 = rand.nextInt(3)+1;
}

System.out.println("Choose A Door");
System.out.println(" _____ _____ _____ ");
System.out.println("| | | | | |");
System.out.println("| 1 | | 2 | | 3 |");
System.out.println("| | | | | |");
System.out.println("| | | | | |");
System.out.println("|_____| |_____| |_____|");
System.out.println("\n");


int yourdoor = scan.nextInt();
System.out.println("Your Door: "+yourdoor);

if (door1 == 1 || door1 == 2){
door1 = gdoor1;}
if (door2 == 1 || door1 == 2){
door2 = gdoor2;}
if (door3 == 1 || door1 == 2){
door3 = gdoor3;}

if(door1 == 3){
door1 = cdoor;}
if(door2 == 3){
door2 = cdoor;}
if(door3 == 3){
door3 = cdoor;}

System.out.println("Value = "+cdoor);




}
}

我正在制作蒙蒂霍尔游戏节目。我对此很陌生,我只是想知道为什么最后当我打印出 cdoor 时为什么它总是打印出 0。我希望它打印出值 3 因为我认为它们会相等,因为 --This Part

    if(door1 == 3){
door1 = cdoor;}
if(door2 == 3){
door2 = cdoor;}
if(door3 == 3){
door3 = cdoor;}

最佳答案

因为cdoor始终为0。它永远不会被修改。也许你的意思是,

if (door1 == 3) {
cdoor = door1;
}
if (door2 == 3) {
cdoor = door2;
}
if (door3 == 3) {
cdoor = door3;
}

关于java - 试图让值相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33512505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com