Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.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 我的if语句每次都返回错误的值,是我的数组吗?_Java_Arrays_If Statement - Fatal编程技术网

Java 我的if语句每次都返回错误的值,是我的数组吗?

Java 我的if语句每次都返回错误的值,是我的数组吗?,java,arrays,if-statement,Java,Arrays,If Statement,每次我输入正确的答案(System.out.println(“Hello World!”);)它都会显示错误。我已经搜索了可能的解决方案,现在我已经浏览了整个代码三次,非常感谢任何帮助或指导。使用equals或equalsIgnoreCase来比较java中的字符串。不要使用==运算符来比较字符串。使用equals或equalsIgnoreCase来比较java中的字符串。不要使用==运算符来比较字符串。使用equals或equalsIgnoreCase来比较java中的字符串。不要使用==运算

每次我输入正确的答案(
System.out.println(“Hello World!”);
)它都会显示错误。我已经搜索了可能的解决方案,现在我已经浏览了整个代码三次,非常感谢任何帮助或指导。

使用
equals
equalsIgnoreCase
来比较java中的字符串。不要使用
==
运算符来比较字符串。

使用
equals
equalsIgnoreCase
来比较java中的字符串。不要使用
==
运算符来比较字符串。

使用
equals
equalsIgnoreCase
来比较java中的字符串。不要使用
==
运算符来比较字符串。

使用
equals
equalsIgnoreCase
来比较java中的字符串。不要使用
=
运算符来比较字符串。

java中的字符串是对象,因此如果它们是相同的对象,而不是包含相同的值,则执行字符串==字符串比较。相反,尝试使用
string1.equals(string2)
java中的字符串是对象,因此如果它们是相同的对象,而不是包含相同的值,则执行String==String比较。相反,尝试使用
string1.equals(string2)
java中的字符串是对象,因此如果它们是相同的对象,而不是包含相同的值,则执行String==String比较。相反,尝试使用
string1.equals(string2)
java中的字符串是对象,因此如果它们是相同的对象,而不是包含相同的值,则执行String==String比较。相反,请尝试使用
string1.equals(string2)

如果()中有print语句,则检查条件时可能存在重复项!这是错误的,请阅读。如果这样做没有帮助,请提供一个示例来说明您的问题。此外,您的do while条件不是有效的表达式:您需要==比较运算符,而不是=赋值运算符。如果()中有print语句,则可能重复您正在检查的条件!这是错误的,请阅读。如果这样做没有帮助,请提供一个示例来说明您的问题。此外,您的do while条件不是有效的表达式:您需要==比较运算符,而不是=赋值运算符。如果()中有print语句,则可能重复您正在检查的条件!这是错误的,请阅读。如果这样做没有帮助,请提供一个示例来说明您的问题。此外,您的do while条件不是有效的表达式:您需要==比较运算符,而不是=赋值运算符。如果()中有print语句,则可能重复您正在检查的条件!这是错误的,请阅读。如果这样做没有帮助,请提供一个示例来说明您的问题。此外,您的do while条件不是有效的表达式:您需要==比较运算符,而不是=赋值运算符谢谢!你的帖子解决了我的问题和一个同事的问题!非常感谢。你的帖子解决了我的问题和一个同事的问题!非常感谢。你的帖子解决了我的问题和一个同事的问题!非常感谢。你的帖子解决了我的问题和一个同事的问题!
import java.util.Scanner;
public class Start
{

public static void main(String[] args) 
{
    Scanner reader = new Scanner(System.in);
    String name = null, helloworlduserattempt = null;
    Boolean helloworldcorrect;

    System.out.println("Welcome to the Java Teacher!");
    System.out.println();
    System.out.println("Type in your name");
    name = (reader.nextLine());
    System.out.println("First " + name + ", lets go over some basics. \nAnything you type to the console in Java Teacher will appear like this;");
    System.out.println();
    System.out.println("___________________________________________________________________________________________");
    System.out.println();
    System.out.println("*your printed text here*");
    System.out.println();
    System.out.println("___________________________________________________________________________________________");

    System.out.println("\n\nThe first exercise is called \"hello world\". This is the starting point for most people while learning how to code.\nThis simply entails writting the phrase \"hello world!\" to the console.");
    System.out.println("\nTo do this, we need to type in \"System.out.println(\"Hello World\");\"");
    System.out.println("\nLets have a look at what that actually means. System.out.println basically tells the system to output to the console the following message on a new line.\nYou could type print instead of println, but this would not write to a new line. Also, notice that System has a capital S");


    System.out.println("Now you try! type in what you think will print \"Hello World!\" to the console");

    do 
    {
        helloworlduserattempt = (reader.nextLine());

        String[] array = helloworlduserattempt.split("\""); 
        array[0] = array[0] + "\"";
        array[2] = "\"" + array[2];
        System.out.println(array[0] + array[1] + array [2]);
        if (helloworlduserattempt == "System.out.println(\"Hello World!\");")
        {
           System.out.println("___________________________________________________________________________________________");
    System.out.println("Hello World!");
    System.out.println("___________________________________________________________________________________________");
    System.out.println("Well done " + name  + "! that was perfect");
    helloworldcorrect = true;
        }
    else if (array[0] == "System.out.println(\"" && array[2] == "\");")
    {
    System.out.println("___________________________________________________________________________________________");
    System.out.println(array[1]);
    System.out.println("___________________________________________________________________________________________");
    System.out.println("youve got the code right " + name + ", but the actual text is incorrect");
    helloworldcorrect = false;
    }
    else 
        {
        System.out.println("___________________________________________________________________________________________");
        System.out.println("Error");
        System.out.println("___________________________________________________________________________________________");
        System.out.println("Oops! thats not quite right " + name + ", try again. remember you can look up at what i said earlier!");
        helloworldcorrect = false;
        }
    }
    while (helloworldcorrect = false);
}
}