package lianxi3;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import static javax.print.attribute.standard.MediaPrintableArea.MM;
public class Test {
public static void main(String[] args) throws ParseException {
/*
需求: 键盘录入生日, 格式: yyyy年MM月dd日. 求出你来这个世界上多少天
思路:
天数 = 今天 - 出生日期
如何获取今天毫秒值: new Date().getTime()
如何将出生日期String转long毫秒值: String -SimpleDateFormat-> Date -> long
如何计算天数: 毫秒差 / 1000 / 24
*/
System.out.println("您的生日是:yyyy-MM-dd");
Scanner sc=new Scanner(System.in);
String birthDay = sc.nextLine();SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date birth = sdf.parse(birthDay);
long time1=birth.getTime();Date nowBirth = new Date();
long time2=nowBirth.getTime();long days=(time2-time1)/1000/60/60/24;
System.out.println(days);}
}
import java.util.ArrayList;
import java.util.Collections;
public class LianXi3 {
public static void main(String[] args) {
String[] colors={"♠","♣","方片","♥"};
String[] numbers={"2","A","K","Q","J","10","9","8","7","6","5","4","3"};
ArrayList<String> poker=new ArrayList<>();
poker.add("大王");
poker.add("小王");
for (String c : colors) {
for (String n : numbers) {
poker.add(c+n);
}
}
Collections.shuffle(poker);
/*
创建4个ArrayList集合, 分别表示3个玩家和底牌
for循环遍历poker集合
如果 索引 >= 51, 存入底牌集合
如果 索引 % 3 == 0, 存入玩家1集合
如果 索引 % 3 == 1, 存入玩家2集合
如果 索引 % 3 == 2, 存入玩家3集合*/
ArrayList<String> play=new ArrayList<>();
ArrayList<String> play2=new ArrayList<>();
ArrayList<String> play3=new ArrayList<>();
ArrayList<String> play4=new ArrayList<>();
for (int i = 0; i < poker.size(); i++) {
if (i>=51){
play.add(poker.get(i));
}else if (i%3==0){
play2.add(poker.get(i));
} else if (i%3==1){
play3.add(poker.get(i));
}else if (i%3==2){
play4.add(poker.get(i));
}
}
System.out.println(play);
System.out.println(play2);
System.out.println(play3);
System.out.println(play4);}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |