做了一个模拟斗地主的程序,代码如下:
package com.zhongruan.test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Test0808 {
public static void main(String[] args) {
String[] colors = new String[]{“红桃”, “黑桃”, “梅花”, “方片”};
String[] numbers = new String[]{“A”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”};
List pokers = new ArrayList<>();
for (String color : colors) {
for (String number : numbers) {
String poker = number + color;
pokers.add(poker);
}
}
pokers.add(“大王”);
pokers.add(“小王”);
System.out.println(pokers);
Collections.shuffle(pokers);
System.out.println(pokers);
List dipai = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < 3; i++) {
int index = random.nextInt(pokers.size()-1);
String pai = pokers.remove(index);
dipai.add(pai);
}
System.out.println(pokers);
System.out.println(dipai);
List<String> zhangyule=new ArrayList<>();
List<String> hualili=new ArrayList<>();
List<String> jiangxinwei=new ArrayList<>();
for(int i=0;i<pokers.size();i++){
String pai=pokers.get(i);
int mod=i%3;
if(mod==0){
zhangyule.add(pai);
}else if(mod==1){
hualili.add(pai);
}else{
jiangxinwei.add(pai);
}
}
System.out.println("zhangyule: "+zhangyule);
System.out.println("hualili: "+hualili);
System.out.println("jiangxinwei: "+jiangxinwei);
int dizhu=random.nextInt(3);
if(dizhu==0){
zhangyule.addAll(dipai);
}else if(dizhu==1){
hualili.addAll(dipai);
}else{
jiangxinwei.addAll(dipai);
}
System.out.println("zhangyule: "+zhangyule);
System.out.println("hualili: "+hualili);
System.out.println("jiangxinwei: "+jiangxinwei);
}
}
其次jdbc七句话:
jdbc
//1.加载驱动
//2.创建连接
//3.写sql语句
//4.得到statement对象
//5.执行sql得到结果集
//6.处理结果集
//7.关闭资源