随机产生两个整数,随机数的范围均是[1,100],定义方法求这两个整数的和并打印和值
在主方法中调用这个求和方法得到结果值,并打印
package com.it;
import java.util.Random;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Random r = new Random();
int a = r.nextInt(100)+1;
System.out.println("a的值为:"+a);
int b = r.nextInt(100)+1;
System.out.println("b的值为:"+b);
getSum(a,b);
}
public static void getSum(int a, int b) {
System.out.println("a+b的值为:");
System.out.println(a+b);
}
}