Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法从InputStreamReader中的System.in返回结果_Java_Inputstreamreader_System.in - Fatal编程技术网

Java 无法从InputStreamReader中的System.in返回结果

Java 无法从InputStreamReader中的System.in返回结果,java,inputstreamreader,system.in,Java,Inputstreamreader,System.in,我在返回颜色字符串时遇到问题。出于某种原因,它不会返回num。我不确定是否需要用else插入if语句的结尾,但我觉得这就是catch语句if的用途 主类 测试班 您的代码示例运行良好。我在测试中添加了以下行,并按预期打印颜色: public static void main(String[] args) { Computer a = new Computer(); System.out.println(a.getProcessor()); } 根据需要打印蓝色或红色 package e

我在返回颜色字符串时遇到问题。出于某种原因,它不会返回num。我不确定是否需要用else插入if语句的结尾,但我觉得这就是catch语句if的用途

主类 测试班
您的代码示例运行良好。我在测试中添加了以下行,并按预期打印颜色:

public static void main(String[] args) {
  Computer a = new Computer();
  System.out.println(a.getProcessor());
}
根据需要打印
蓝色
红色

package edu.computer.test;

public class ComputerTester {
  public static void main(String[] args) {
    Computer a = new Computer();
    a.getProcessor();
  }
}
public static void main(String[] args) {
  Computer a = new Computer();
  System.out.println(a.getProcessor());
}