基础小程序

一、

package com.hp.dao;
 
 
import java.util.Scanner;
 
public class ad {
    public static class Mgan {
 
        private String[] str={"枪","死","打劫","共产党"};
        public static void main(String[] args) {
            Mgan mgan = new Mgan();
            mgan.test();
        }
        public void test(){
            System.out.println("请输入字符串:");
            Scanner sc= new Scanner(System.in);
            String s=sc.next();
            for (String word:str) {
                if (word.contains(word)){
                    int len=word.length();
                    String th="*";
                    for (int j = 0; j < len-1; j++) {
                        th+="*";
                    }
                    s=s.replace(word, th);
                }
            }
            System.out.println(s);
        }
 
    }
}

二、

package com.hp.dao;
import javax.swing.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
 
public class GdDate {
    public static class Countdown {
        long gdDate;
        long newDate;
        long millisecond;
        long day,hour,minutes,seconds;
 
        public Countdown(){
            CDown();
        }
 
        private void CDown() {
            Timer t = new Timer();
            final JLabel j = new JLabel();
            t.schedule(new TimerTask() {
                @Override
                public void run() {
                    Calendar c = Calendar.getInstance();
                    c.set(2022,10,1,0,0,0);
                    gdDate = c.getTimeInMillis();
                    newDate = new Date().getTime();
                    millisecond = gdDate - newDate;
                    System.out.println("毫秒差为:" + millisecond);
                    day = ((millisecond / 1000) / (3600 * 24));
                    hour = ((millisecond / 1000) - day * 86400) / 3600;
                    minutes = ((millisecond / 1000) - day * 86400 - hour * 3600) / 60;
                    seconds = (millisecond / 1000) - day * 86400 - hour * 3600 - minutes * 60;
                    System.out.println((" 国庆倒计时还有:" + day + " 天 " + hour + " 时 " + minutes + " 分 " + seconds + " 秒 "));
                }
            },0,1000);
        }
 
        public static void main(String[] args) {
            new Countdown();
        }
 
    }
    }
 

三、

package com.hp.dao;
 
import java.util.HashMap;
import java.util.Map;
 
public class Xingshi {
        public static void main(String[] args) {
            String[] name = new  String[]{"张三","李四","王二","王五","张三丰","李利","张涛"};
            Map map = new HashMap();
            String zhang = null;
            String wang = null;
            String li = null;
            String liu = null;
 
            int num = 0;
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            for (int i =0 ; i<name.length;i++) {
                if (name[i].contains("张")){
                    zhang = name[i];
                    num++;
                }
                if (name[i].contains("李")){
                    li = name[i];
                    //System.out.println(zhang.charAt(0));
                    num1++;
                }
                if (name[i].contains("王")){
                    liu = name[i];
                    //System.out.println(zhang.charAt(0));
                    num2++;
                }
                if (name[i].contains("王")){
                    wang = name[i];
                    //System.out.println(zhang.charAt(0));
                    num3++;
                }
            }
            map.put(zhang.charAt(0),num);
            map.put(li.charAt(0),num1);
            map.put(liu.charAt(0),num1);
            map.put(wang.charAt(0),num1);
            System.out.println(map);
        }
    }
 
 

四、

package com.hp.demo1;
/**
 * 一张扑克牌类
 *      花色:♠ ♥ ♦ ♣
 *      牌号:A 2 3 4 5 6 7 8 9 10 J Q K
 *      大王、小王
 */
public class PokerCard {
        private String color;   //花色
        private String cardNum; //牌号
 
        public PokerCard() {
        }
 
        public PokerCard(String color, String cardNum) {
            this.color = color;
            this.cardNum = cardNum;
        }
 
        public String getColor() {
            return color;
        }
 
        public void setColor(String color) {
            this.color = color;
        }
 
        public String getCardNum() {
            return cardNum;
        }
 
        public void setCardNum(String cardNum) {
            this.cardNum = cardNum;
        }
 
        @Override
        public String toString() {
            return color + cardNum ;
        }
    }
 
package com.hp.demo1;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
/*
* 扑克
* 花色
* 牌号
* 大王、小王
*
* 1.生成一副牌
* 2.然后发牌
* */
public class Poker {
        //一副牌
        private static List<PokerCard> pokerList;
        private static ArrayList<PokerCard> A;
        private static ArrayList<PokerCard> B;
        private static ArrayList<PokerCard> C;
 
 
        //无参构造器,初始化一副牌
        public Poker() {
            String[]colors={"♠","♥","♣","♦"};
            pokerList = new ArrayList<>();
            A = new ArrayList<>();
            B = new ArrayList<>();
            C = new ArrayList<>();
            //接下来生成牌
            //A牌的四种花色
            for (int i = 0; i < colors.length; i++) {//四种花色
                PokerCard pc = new PokerCard(colors[i], "A");
                pokerList.add(pc);
            }
            //2-10的牌
            for (int i = 2; i <= 10; i++) {
                //2-10牌的四种花色
                for (int j = 0; j < colors.length; j++) {//四种花色
                    PokerCard pc = new PokerCard(colors[j], i+"");
                    pokerList.add(pc);
                }
            }
            //JQK牌的四种花色
            for (int i = 0; i < colors.length; i++) {//四种花色
                PokerCard pc = new PokerCard(colors[i], "J");
                pokerList.add(pc);
            }
            for (int i = 0; i < colors.length; i++) {//四种花色
                PokerCard pc = new PokerCard(colors[i], "Q");
                pokerList.add(pc);
            }
            for (int i = 0; i < colors.length; i++) {//四种花色
                PokerCard pc = new PokerCard(colors[i], "K");
                pokerList.add(pc);
            }
            //大小王
            PokerCard pc1 = new PokerCard(null, "大王");
            pokerList.add(pc1);
            PokerCard pc2 = new PokerCard(null, "小王");
            pokerList.add(pc2);
        }
        //洗牌
        public static void xipai(){
            Collections.shuffle(pokerList);
        }
 
        //发牌
        public static void fapai(){
            A.clear();
            B.clear();
            C.clear();
            for (int i = 0; i < pokerList.size(); i++) {
                if (i % 3 == 0){
                    A.add(pokerList.get(i));
                }
                if (i % 3 == 1){
                    B.add(pokerList.get(i));
                }
                if (i % 3 == 2){
                    C.add(pokerList.get(i));
                }
            }
        }
 
        public List<PokerCard> getPokerList() {
            return pokerList;
        }
 
        public void setPokerList(List<PokerCard> pokerList) {
            this.pokerList = pokerList;
        }
 
        public static void main(String[] args) {
            Poker poker = new Poker();
            System.out.println(poker.getPokerList());
            xipai();
            fapai();
            System.out.println("张三" + A);
            System.out.println("李四" + B);
            System.out.println("王五" + C);
        }
    }
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值