Lesson_4 作业_2 ---- 数组构建扑克牌
2013-01-14
1 /******************************题目描述*********************************** 2 * 用数组构建一副扑克牌52张(花色和数值),并输出到屏幕。 3 * 提示:可以用二维数组来实现 4 ********************************解题思路*********************************** 5 * 6 * 用一个poker[4][14]来存储信息,每行的第一个位置存放花色,其他的放数字 7 * 8 ********************************注释*************************************** 9 * 2012-1-15 by CocoonFan 10 ****************************************************************************/ 11 12 13 public class 数组构建扑克牌{ 14 public static void main(String [] args){ 15 /*for(int i = 1; i <= 255; i++){ 16 System.out.print( (char)i +"->" + i + " "); 17 }*/ 18 19 String []pokerStr = {"2","3","4","5","6","7","8","9","10","J","Q","K","A"}; 20 String []pokerType = {"黑桃","红桃","方块","梅花"}; 21 String poker[][] = new String[4][14]; 22 for(int i = 0; i < 4; i++){ 23 poker[i][0] = pokerType[i]; 24 for(int j = 0; j< 14; j++){ 25 if(j == 0){ 26 System.out.print(poker[i][j] + " "); 27 continue; 28 } 29 poker[i][j] = pokerStr[j-1]; 30 System.out.print(poker[i][j] + " "); 31 } 32 System.out.println(); 33 } 34 } 35 }
运行结果: