方法

Misama 2014-07-31 01:43:08
package aaa;
import java.util.*;
public class Question2 {

/*1.Get a integer(shuffle times) from keyboard and judge whether it is out of range,
*2.Save the original order of cards into a String[],
*3.Output the original order,
*4.Generate two random number by (int)(Math.random()*52) and assign their value to parameter x and y, then swap String[x] and String[y],
*5.Repeat Step.4 for a required times mentioned above, then output the result.
*/

public static void main(String args[]){//the main method

Scanner cin = new Scanner(System.in);//use Scanner to get the input
int shuffleTimes = cin.nextInt();//the shuffle times

if( shuffleTimes<1 ||shuffleTimes>1000 ){//whether the shuffle times is out of range
System.out.println("ERROR: Input " + shuffleTimes + " out of range, try again!");
return;
}

String[] cards = {"2-Spd","3-Spd","4-Spd","5-Spd","6-Spd","7-Spd","8-Spd","9-Spd","10-Spd","J-Spd","Q-Spd","K-Spd","A-Spd",
"2-Hrt","3-Hrt","4-Hrt","5-Hrt","6-Hrt","7-Hrt","8-Hrt","9-Hrt","10-Hrt","J-Hrt","Q-Hrt","K-Hrt","A-Hrt",
"2-Dmd","3-Dmd","4-Dmd","5-Dmd","6-Dmd","7-Dmd","8-Dmd","9-Dmd","10-Dmd","J-Dmd","Q-Dmd","K-Dmd","A-Dmd",
"2-Clb","3-Clb","4-Clb","5-Clb","6-Clb","7-Clb","8-Clb","9-Clb","10-Clb","J-Clb","Q-Clb","K-Clb","A-Clb"
};//save the original cards

System.out.println("Before shuffle:");
OutputCards.execute(cards);//the output method in OutputCards.java
System.out.println();

System.out.println("After shuffle:");
ShuffleCards.execute(cards, shuffleTimes);//the shuffle method in ShuffleCards.java
OutputCards.execute(cards);//output the final order,over

}

}
...全文
176 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
陌城 2014-07-31
  • 打赏
  • 举报
回复
代码贴出来,你想表达什么呢。
a137655624 2014-07-31
  • 打赏
  • 举报
回复
你到底要干什么

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧