java在按键时打印文本
谁能帮我一下吗
public class DemoTest {
public static void main(String[] args) {
keyPressed();
}
public static void keyPressed() {
//If player presses the key 1 then print the line:
System.out.println("You pressed the key 1");
}
}
现在我想在你按1键时打印出一些东西
# 1 楼答案
这应该是有效的:
try catch块仅用于确保玩家输入一个数字
# 2 楼答案
尝试以下代码行: