public static void main(String[] args) {
try {
Scanner in = new Scanner(System.in);
String ss = in.nextLine();
String[] temp = ss.split(" ");
int person = Integer.parseInt(temp[0]);
int game = Integer.parseInt(temp[1]);
System.out.println("person :"+ person +"game "+ game);
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Error of Input!");
}
System.out.println(game,person);
}
运行的时候显示找不到person和game,小白求解 |
|
![]() 20分 |
public static void main(String[] args) {
int person=0; int game =0; try { Scanner in = new Scanner(System.in); String ss = in.nextLine(); String[] temp = ss.split(” “); 这样就行了 ,作用域的问题。 |
![]() 10分 |
System.out.println(game,person); 看看api 没有 2个 参数的。
其次 ,你 game,person 也访问不到 ,变量的作用范围 不一样 。 |
![]() |
+1 |
![]() 10分 |
作用域问题person,game在try以外都访问不到, 你这样写
public static void main(String[] args) {
int person,game;
try {
Scanner in = new Scanner(System.in);
String ss = in.nextLine();
String[] temp = ss.split(" ");
person = Integer.parseInt(temp[0]);
game = Integer.parseInt(temp[1]);
System.out.println("person :"+ person +"game "+ game);
}catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Error of Input!");
}
System.out.println(game,person);
}
|
![]() |
System.out.println(game,person);
|
![]() |
太谢谢了 |
![]() |
谢谢 |
![]() |
嗯嗯,写c写惯了,结果写成了这样 |
![]() |
哥哥, 你的game和person定义在try里面,然后再外面使用,肯定不行啊
|

