搜索
首页Java错误:在用户输入代码中找不到符号

php小编新一为您解答Java编程中常见问题:“错误:在用户输入代码中找不到符号”。这种错误通常表示编译器无法识别代码中使用的变量或方法,可能是由于拼写错误、作用域问题或未导入相关包等原因导致。在编程过程中遇到这种情况时,需要仔细检查代码,确保所有变量和方法名称都正确无误。同时,确保导入了所需的包和库,以避免出现这种错误。

问题内容

我对编程语言非常陌生,我正在尝试学习 java 语言。

我正在处理用户输入、条件和多个条件。

当我尝试编写自己的代码时,出现错误,这是代码:

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...");
        }    }
}

错误信息:

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

我不明白我应该做什么,要解决什么问题。是“输入”后面的点符号吗?当我删除它时,它也不起作用。

抱歉我的英语不好。

但是,当我删除“input.nexln();”中的“ln”时。有用。我根本不明白。 这是代码:

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...");
        }
    }
}

解决方法

您收到此错误是因为扫描仪类没有名为 nextln() 的方法,应该用于读取输入的方法是 nextline()。 正确的代码是:

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...");
    }    }

以上是错误:在用户输入代码中找不到符号的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:stackoverflow。如有侵权,请联系admin@php.cn删除

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具