有没有人知道如何将整数发送到方法中?我正在努力将主类中生成的整数发送到方法中,有人能帮忙吗?我正在尝试将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);
}
}
}
1条答案
按热度按时间oewdyzsn1#
您可以使用公共静态变量从主函数中调用编号
使用Main.num1调用该号码