netbeans 是否将存储的整数发送到方法?

b1zrtrql  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(151)

有没有人知道如何将整数发送到方法中?我正在努力将主类中生成的整数发送到方法中,有人能帮忙吗?我正在尝试将num1发送到n1,将num2发送到n2。谢谢

public class CompareNumbers {
static void CompareNums(){
    int n1 = num1;
    int n2 = num1;
    if ( n1 == n2)
    {
        System.out.print("The numbers are equal");
    }
    else if ( n1 > n2)
    {
        System.out.print("The first number is greater");
    }
    else if ( n2 > n1)
    {
        System.out.print("The second number is greater");
    }}public static void main(String[] args) {
    CompareNums();
    int max = 100;
    int min = 1; 
    for (int i=1; i<=10; i++)
    {
        int num1 =(int) (Math.random() * (max-min=1) + min); 
        int num2 = (int) (Math.random()* (max-min=1)+ min);
    }

}

}

oewdyzsn

oewdyzsn1#

您可以使用公共静态变量从主函数中调用编号

public class Main{
  public static int num1;
  public static int num2;
}

使用Main.num1调用该号码

相关问题