我刚刚开始学习,我真的很难让我的方法奏效。我尝试全局声明变量 num1 和 num2 ,但没有任何效果。我究竟做错了什么?
import java.util.*;
public class MinMax
{
static Scanner keyboard = new Scanner(System.in);
//a re-useable method to get the numbers
public static void getNumbers()
{
int num1, num2;
System.out.println("Please enter number 1");
num1 = keyboard.nextInt();
System.out.println("Please enter number 2");
num2 = keyboard.nextInt();
}
//getNumbers
public static void printAnswer(int pNum1, int pNum2)
{
if (pNum1 > pNum2)
{
System.out.println("Number 1 is the max number");
}
else
{
System.out.println("Number 2 is the max number");
}
}//printAnswer
public static void main(String [] args)
{
getNumbers();
printAnswer(num1, num2);
getNumbers();
printAnswer(num1, num2);
}//main
}//class