Home > Java > body text

Error: symbol not found in user input code

PHPz
Release: 2024-02-22 12:28:18
forward
485 people have browsed it

php editor Xinyi answers common questions in Java programming: "Error: Symbol not found in user input code". This error usually means that the compiler does not recognize a variable or method used in the code, possibly due to spelling errors, scoping issues, or not importing the relevant package. When you encounter this situation during programming, you need to carefully check the code to ensure that all variable and method names are correct. Also, make sure you import the required packages and libraries to avoid this error.

Question content

I am very new to programming languages ​​and I am trying to learn java language.

I'm dealing with user input, conditions and multiple conditions.

When I try to write my own code, I get an error, this is the code:

import java.util.scanner;

public class main
{
    public static void main (string[] args) {
        scanner input = new scanner(system.in);
        
        system.out.println("masukkan suhu:");
        int temp = input.nextint();
        system.out.println("masukkan hal yang direbus:");
        **string rebusan = input.nextln();**
        
        if ((temp == 100) && (rebusan == "air" || rebusan == "air")) {
            system.out.println("mendidih, segera angkat!");
        } else if ((temp >= 60 && temp <= 100) && (rebusan == "air" || rebusan == "air")) {
            system.out.println("sedikit lagi");
        } else if ((temp >= 25 && temp <= 60) && (rebusan == "air" || rebusan == "air")) {
            system.out.println("masih lama, sabar");
        } else if ((temp >= 1 && temp <= 25) && (rebusan == "air" || rebusan == "air")) {
            system.out.println("baru dinyalain...");
        } else if ((temp >= -300 && temp <= 1) && (rebusan == "air" || rebusan == "air")) {
            system.out.println("beku!");
        } else {
            system.out.println("hmm...");
        }    }
}
Copy after login

error message:

main.java:11: error: cannot find symbol
        string rebusan = input.nextln();
                              ^
  symbol:   method nextln()
  location: variable input of type scanner
Copy after login

I don’t understand what I should do and what problem I should solve. Is it the dot symbol after "input"? When I remove it it doesn't work either.

Sorry for my bad English.

But when I remove the "ln" in "input.nexln();". it works. I don't understand it at all. This is the code:

import java.util.Scanner;

public class Main
{
    public static void main (String[] args) {
        Scanner input = new Scanner(System.in);
        
        System.out.println("Masukkan Suhu:");
        int temp = input.nextInt();
        System.out.println("Masukkan Hal yang direbus:");
        **String rebusan = input.next();**
        
        if ((temp == 100) && (rebusan == "air" || rebusan == "Air")) {
            System.out.println("Mendidih, segera angkat!");
        } else if ((temp >= 60 && temp <= 100) && (rebusan == "air" || rebusan == "Air")) {
            System.out.println("Sedikit lagi");
        } else if ((temp >= 25 && temp <= 60) && (rebusan == "air" || rebusan == "Air")) {
            System.out.println("Masih lama, sabar");
        } else if ((temp >= 1 && temp <= 25) && (rebusan == "air" || rebusan == "Air")) {
            System.out.println("Baru dinyalain...");
        } else if ((temp >= -300 && temp <= 1) && (rebusan == "air" || rebusan == "Air")) {
            System.out.println("Beku!");
        } else {
            System.out.println("Hmm...");
        }
    }
}
Copy after login

Workaround

You are getting this error because the scanner class does not have a method named nextln(), the method that should be used to read the input is nextline(). The correct code is:

Scanner input = new Scanner(System.in);

    System.out.println("Masukkan Suhu:");
    int temp = input.nextInt();
    System.out.println("Masukkan Hal yang direbus:");
    String rebusan = input.nextLine();

    if ((temp == 100) && (rebusan == "air" || rebusan == "Air")) {
        System.out.println("Mendidih, segera angkat!");
    } else if ((temp >= 60 && temp <= 100) && (rebusan == "air" || rebusan == "Air")) {
        System.out.println("Sedikit lagi");
    } else if ((temp >= 25 && temp <= 60) && (rebusan == "air" || rebusan == "Air")) {
        System.out.println("Masih lama, sabar");
    } else if ((temp >= 1 && temp <= 25) && (rebusan == "air" || rebusan == "Air")) {
        System.out.println("Baru dinyalain...");
    } else if ((temp >= -300 && temp <= 1) && (rebusan == "air" || rebusan == "Air")) {
        System.out.println("Beku!");
    } else {
        System.out.println("Hmm...");
    }    }
Copy after login

The above is the detailed content of Error: symbol not found in user input code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!