如何编写一个生成 0 到 50 之间的三个随机整数并计算平均值的 Java 程序?
我的代码是这样的:
import java.util.Random;
public class RandomAverage {
public static void main(String[] args)
{
int num1,num2,num3;
int sum,average;
Random random = new Random();
num1 = random.nextInt(51);
num2 = random.nextInt(51);
num3 = random.nextInt(51);
sum = num1+ num2+ num3;
average = sum/3;
System.out.print("The sum of them is :" + sum);
System.out.print("The average of them is :" + average);
}
}
但输出说:
Error: Could not find or load main class stringchecker.StringChecker
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
那有什么问题?