第一题:需求实现
模拟大乐透号码:
一组大乐透号码由10个1-99之间的数字组成
定义方法,打印大乐透号码信息
代码实现,效果如图所示:
开发提示:
使用数组保存录入的号码
参考答案:
public class Test1 {
public static void main(String[] args) {
int[] arr = {10,20,30,40,50, 60,66,70,80,99};
printNum(arr);
}
public static void printNum(int[] arr) {
System.out.println("您的大乐透号码为:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
}
第二题:需求实现
打印扑克牌.
代码实现,效果如图所示:
开发提示:
使用两个字符串数组,分别保存花色和点数
public class Test2 {
public static void main(String[] args) {
// 花色数组
String[] hs = {"黑桃","红桃","梅花","方片"};
// 点数数组
String[] ds = {"A","2","3","4", "5","6","7","8","9","10","J","Q","K"};
printCard(hs,ds);
}
public static void printCard(String[] hs ,String[] ds){
for (int hs_index = 0; hs_index < hs.length; hs_index++) {
for (int ds_index = 0; ds_index < ds.le