繁体   English   中英

如何解决Java中的“错误:找不到符号”

[英]how do I fix this “error: cannot find symbol” in Java

public class Passcode 
{ 
    public static void main(String[] args)
    { 
        System.out.printf("%5s","What is the password\n");    // ask user what the code is// 

        String flake= StdIn.readString();// take in input from user// 

        String cake= "cookie"; // not complete yet but will use this in an if statement// 

    }
}

我想您程序中的StdIn.readString来自外部软件包。 可能来自普林斯顿大学的Java软件包?

如果是这样,您应该:

  1. 在开始时导入包。 例如,

    导入abc.def.StdIn;

  2. 将您使用的jar包目录添加到CLASSPATH 您可能会在Google上找到许多有关如何执行此操作的有用信息。

我认为您的导入语句可能缺少一些内容。 您可能想尝试以下代码:

import java.io.*;

public class Passcode 
{ 
    public static void main(String[] args) throws IOException
    { 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.printf("%5s","What is the password\n");    // ask user what the code is// 

        //String flake= StdIn.readString();// take in input from user// 
        String flake = br.readLine();
        System.out.println(flake);

        String cake= "cookie"; // not complete yet but will use this in an if statement// 

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM