【问题标题】:Mistake Integer customized value Java错误整数自定义值Java
【发布时间】:2023-03-07 20:49:03
【问题描述】:

如何在以下程序中读入整数?它不起作用。目前无法编译。

/**
 * Main class of the Java program. 
 * 
 */
import java.util.Scanner;

//...
class Scanner{
    Scanner in = new Scanner(System.in);
    int num = in.nextInt();
}


public class Main {

    public static void main(String[] args) {

        // we print a heading and make it bigger using HTML formatting
        System.out.println("<h4>-- Binaere Suche --</h4>");
        int anzahl = 0; int zahl;

    }
}

【问题讨论】:

  • 然后呢?仍然缺少一些东西。
  • ./Root/src/Main.java:23: 错误:int 不能被取消引用 zahl.Scan(); ^ 注意:./Root/src/BinarySearchFactory.java 使用未经检查或不安全的操作。注意:使用 -Xlint:unchecked 重新编译以获取详细信息。 1 个错误
  • 在println下使用Scanner sc = new Scanner(System.in); int zahl = sc.nextInt();去掉Scanner类(java已经有)

标签: java class input compiler-errors main


【解决方案1】:
import java.util.Scanner;

// This will print what you want but will not make it look bigger as it
// will get printed in console
public class Main {

    public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    int num = in.nextInt();
 // we print a heading and make it bigger using HTML formatting
        System.out.println("<h4>--"+num+" --</h4>");

    }
}

【讨论】:

  • 谢谢,现在可以编译了。
猜你喜欢
  • 2015-07-14
  • 1970-01-01
  • 2018-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-21
  • 2017-02-10
  • 2019-02-07
相关资源
最近更新 更多