1.设计一个敏感词过滤程序
WordFilter类
属性:数组类型[]存放敏感词
设计一个方法,调用这个方法(传参,可能会包含敏感词的字符串),返回过滤后的新的字符串
public static String filter(String word){
//过滤代码
return word;
}
要求:可以添加多个要过滤的敏感词{"枪","死","打劫","共产党"}
如果是一个字符就替换一个*,如果两个字符就替换**,以此类推
package com.zuoye.demo01;
public class Mgc {
private static String m(String s) {
String [] str ={"枪","死","打劫","共产党"};
for (int i = 0; i < str.length; i++) {
if (s.contains(str[i])) {
s = s.replace(str[i],"*");
s = s.replace(str[2],"**");
s = s.replace(str[3],"***");
System.out.println(s);
}
}
return s;
}
public static void main(String[] args) {
String s ="不要动!打劫!再动一枪崩死你!!!" + "n" + "共产党万岁";
m(s);
}
}
2.国庆倒计时
创建一个国庆节2022年10月1日的日期对象gdDate
gdDate获取从1970年过了多少毫秒数
while(){
创建一个当前日期对象nowDate
nowDate获取从1970年过滤多少毫秒数
gdDate的毫秒数-nowDate的毫秒数,得到毫秒差
把毫秒数转为:xx天xx小时xx分钟xx秒
sout打印输出拼接好的倒计时
Thread.sleep(1000);
}
package com.zuoye.demo01;
import javax.swing.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Guoqing {
long longTime;
long currentTime;
long distTime;
long day, hour, minutes, seconds;
public Guoqing() {
CDown();
}
public void CDown() {
Timer t = new Timer();
final JLabel jl = new JLabel();
final JFrame jf = new JFrame();
jf.add(jl);
jf.setVisible(true);
jf.setSize(400, 150);
jf.getDefaultCloseOperation();
t.schedule(new TimerTask() {
@Override
public void run() {
Calendar cal = Calendar.getInstance();
cal.set(2022, 10, 1, 0, 0, 0);
longTime = cal.getTimeInMillis();
currentTime = new Date().getTime();
distTime = longTime - currentTime;
System.out.println("毫秒差为:" + distTime);
day = ((distTime / 1000) / (3600 * 24));
hour = ((distTime / 1000) - day * 86400) / 3600;
minutes = ((distTime / 1000) - day * 86400 - hour * 3600) / 60;
seconds = (distTime / 1000) - day * 86400 - hour * 3600
- minutes * 60;
System.out.println((" 国庆倒计时" + day + " 天 " + hour + "小时 :" + minutes
+ "分钟 :" + seconds + "秒"));
}
}, 0, 1000);
}
public static void main(String[] args) {
new Guoqing();
}
}
3.使用Map集合来做一个不同姓氏人数的统计
有一个String数组保存着10个人的姓名{"张三","李四","王二"...}
通过程序设计,把不同姓氏的姓氏和人数保存到Map集合中
package com.zuoye.demo02;
import java.util.HashMap;
import java.util.Map;
public class NameStatistics {
public static void main(String[] args) {
String[] name = new String[]{"凌不疑","凌宜","程少商","程止","程承","程始","程颂","程少宫","程姎","万萋萋","万松柏","楼垚","楼犇"};
Map map = new HashMap<>();
String ling = null;
String cheng = null;
String wan = null;
String lou = null;
int num = 0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
for (int i =0 ; i
4.模拟扑克牌
花色:♠ ♥ ♦ ♣
* 牌号:A 2 3 4 5 6 7 8 9 10 J Q K
* 大王、小王
*
* 1.生成一副牌
* 2.然后发牌
package com.zuoye.demo02;
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.zuoye.demo02;
import com.baidu.demo.PukerCard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Poker{
private static List pokerList;
private static ArrayList A;
private static ArrayList B;
private static ArrayList 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], "Q");
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 static List getPokerList() {
return pokerList;
}
public static void setPokerList(List pokerList) {
Poker.pokerList = pokerList;
}
public static ArrayList getA() {
return A;
}
public static void setA(ArrayList a) {
A = a;
}
public static ArrayList getB() {
return B;
}
public static void setB(ArrayList b) {
B = b;
}
public static ArrayList getC() {
return C;
}
public static void setC(ArrayList c) {
C = c;
}
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);
}
}



