【发布时间】:2020-04-11 03:27:13
【问题描述】:
如果我将 if 中的 typedNum 替换为 x
((typedNum.nextInt() > 21 && typedNum.nextInt()< 30)),那么它可以完美运行。为什么会这样?
import java.util.Scanner;
public class Main {
public static int number(Scanner typedNum) {
int x = 0;
int i = 0;
while (i < 1) {
x = typedNum.nextInt();
if ((typedNum.nextInt() > 21 && typedNum.nextInt()< 30)) {
System.out.println("in range");
i=1;
}
else {
System.out.println("Not in range");
}
}
System.out.println(x);
return (x);
}
public static void main(String[] args) {
Scanner y = new Scanner(System.in);
number(y);
}
}
【问题讨论】:
标签: java