Java code execution error

Asked 2 years ago, Updated 2 years ago, 22 views

I learned Java almost for the first time, and I saw what was in the example.

  import util java.Scanner;

public class A3 {
public static void main(String [] args) {
    String str = "hello";
    String input = null;

    Scanner magic = new Scanner (System.in);
    System.out.print("please enter the Text:");
    input = magic.next();

    if (str == input) {
        System.out.println("Text is match!");

    } else {
        System.out.println("Error! Text isn't match!");


                }
    magic.close();}
        }

I tested and ran

This screen appears, and it doesn't work. JRE10 is in use.

What's the problem?

java

2022-09-21 21:48

2 Answers

delete jdk 10 version and install 8 version

I don't think Eclipse can support 10.

Currently, support for version 9 is in full swing, so install 8 and test it.


2022-09-21 21:48

I don't know if you've checked it out

import java.util.Scanner;

public class A3 { public static void main(String[] args) { String str = "hello"; String input = null;

    Scanner magic = new Scanner(System.in);
    System.out.print("please enter the Text:");
    input = magic.next();

    if (str.equals(input)) {
        System.out.println("Text is match!");

    } else {
        System.out.println("Error! Text isn't match!");

    }
    magic.close();
}

}

You can do it like this.


2022-09-21 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.