问题描述
public class Monday {public static int[] getRed() {int a[] = new int[6];// 获奖号码for (int i = 0; i < 6; i++) {while (true) {int k = 0;a[i] = (int) (Math.random() * 33) + 1;for (int j = 0; j < i; j++) {if (a[i] == a[j]) {k = 1;}}if (k == 0) {break;}}}return a;}public static int getBule() {int b = (int) (Math.random() * 16);return b;}public static void main(String[] args) {System.out.println(getRed()+" "+getBule());}}怎么打印出getRed 数组里面的元素!! 望高手让我能触类旁通,不胜感激!!!!
解决方案
循环叠代打印咯int[] red = getRed();for(int n : red) { System.out.print(n); System.out.print(",");}System.out.println();
解决方案二:
getRed() 是一个数组,只会打印出地址的你要重写 toStinrg()方法或者像楼上的那样处理
解决方案三:
没懂,你要实现什么抽奖功能吗?
时间: 2024-11-15 06:03:50