我如何解决这个问题"错误:找不到符号"在Java中

时间:2016-10-23 01:21:18

标签: 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// 

    }
}

2 个答案:

答案 0 :(得分:1)

我认为程序中的StdIn.readString来自外部程序包。可能来自普林斯顿的java包吗?

如果是这样,你应该:

  1. 在开头导入包。例如,
      

    import abc.def.StdIn;

  2. 将您使用的jar包目录添加到CLASSPATH。您可以在google上找到有关如何执行此操作的大量有用信息。

答案 1 :(得分:0)

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

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// 

    }
}