谁能告诉我如何将 Scanner 类作为函数参数引用?我的意思是: 如果我有一个主要功能:
public static void main(String[] args)
{ Scanner in = new Scanner(System.in);
int a = nextInt();
int b = nextInt();
isPositive(<how do i refer to a and b here>);
}
public static bolean isPositive(Scanner in)
{ <how do I refer to a and b here, to check if (a - b) > 0 )
}
谢谢!
最佳答案
您遇到的问题之一是无法正确调用扫描仪。
int a = in.nextInt();
int b = in.nextInt();
从这里您可以将从扫描仪获得的值传递到您的 isPositive 类中
public static boolean isPositive(int a, int b) { }
关于java - 扫描仪类作为函数参数 - 如何引用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60218065/