public class StarRandom {
public static void main(String[] args) {
Random r = new Random();
int number = r.nextInt(3) + 5;
System.out.println("本次随机生成的是高为" + number + "的三角形");
for (int i = 0; i <= number; i++) {
for (int j = 1; j <= i; j++) {
if(j != i){
System.out.print("*" + " ");
}
else {
System.out.println("*");
}
}
}
}
}
public class Test03_04 {
public static void main(String[] args) {
Random r = new Random();
int[] score = new int[5];
int sum = 0;
double average;
int count = 0;
System.out.println("该班级的分数为:");
for (int i = 0; i < score.length; i++) {
score = r.nextInt(101);
System.out.print(score + " ");
}
for (int i = 0; i < score.length; i++) {
if(score < 60) {
count ++;
}
}
System.out.println();
System.out.println("该班有"+ count +"个不及格的人");
System.out.println("该班级的总分为:");
for (int j = 0; j < score.length; j++) {
sum += score[j];
}
System.out.println(sum);
System.out.println("该班级的平均分为:");
average = sum / score.length;
System.out.println(average);
}
}