java - 错误整数自定义值Java
问题描述
如何在以下程序中读入整数?它不起作用。目前无法编译。
/**
* 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;
}
}
解决方案
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>");
}
}
推荐阅读
- azure - 如何使用“创建容器组”操作将私有 docker hub 映像部署到 Azure 逻辑应用
- angular - 如何使 stenciljs 组件在 Edge 上使用 angular 2+
- java - 引发 Java 错误时停止运行 .jar 的 AppleScript
- database - 关系检索 Neo4j 的问题
- markdown - 在降价表中换行
- python - 如何在python中将文件夹从服务器复制到客户端
- mysql - 我如何在 sql 中限制,如果选择了一个表行,则仅显示另一表中的相应项目?
- javascript - 垂直滚动时水平滚动?
- c++ - 对 std::reference_wrapper 的大小有任何保证吗?
- python - 我应该何时声明自定义异常?