HWK0728

import java.util.ArrayList;
import java.util.Scanner;

public class RE {
    
    
    

    public void search(String[] a, String in) {
        int lenIn = in.length();
        int count = 0;
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length() - lenIn; j++) {
                if (in.equals(a[i].subSequence(j, j + lenIn))) {
                    list.add(a[i]);
                    count++;
                }
            }
        }
        if (count == 0) {
            System.out.println("无相关新闻");
        } else {
            System.out.println(list);
        }

    }

    public RE() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        
        
        
        
        RE r = new RE();

        Scanner sc = new Scanner(System.in);
        System.out.println("===1===");
        boolean again = true;

        do {

            System.out.println("输入用户名( 8-12位,首位字母,其余是字母 数字 $ )");
            String reAccount = sc.next();
            String re1 = "^[a-zA-Z][\\da-zA-Z$]{7,11}$";
            System.out.println("用户名" + reAccount.matches(re1));

            System.out.println("输入网址");
            String reWeb = sc.next();
            String web = "^\\p{Alpha}{1,}.com$";
            System.out.println("网址类型" + reWeb.matches(reWeb));

            System.out.println("again?( y / other )");
            String ag = sc.next();
            if (ag.equals("y")) {
                System.out.println("One more time!");
            } else {
                again = false;
            }
        } while (again);

        System.out.println("");
        
        
        
        
        
        
        System.out.println("===2===");
        again = true;

        do {

            String[] news = { "奋进新征程 建功新时代 非凡十年 “互联护苗2022”.", "60年历史再见!雪碧将放弃绿瓶包装,改为透明瓶身", "湖南:高质量发展闯新路 展现新作为新担当.",
                    "山西刀削面登上舌尖上的宇宙。", "小吕刀削面港股敲钟!" };

            System.out.println("请输入关键字");
            r.search(news, sc.next());

            System.out.println("again?( y / other )");
            String ag = sc.next();
            if (ag.equals("y")) {
                System.out.println("One more time!");
            } else {
                again = false;
            }
        } while (again);
        System.out.println("");
        
        
        
        
        
        System.out.println("===3===");

        again = true;

        do {
            System.out.println("输入四个字母(否则报错!)");
            

//            StringBuilder t = new StringBuilder( sc.next());
//            System.out.println(t.reverse());
            StringBuilder a = new StringBuilder(sc.next());
            char tt = a.charAt(1);
            a.setCharAt(1, a.charAt(2));
            a.setCharAt(2, tt);
            System.out.println(a);
            

            System.out.println("again?( y / other )");
            String ag = sc.next();
            if (ag.equals("y")) {
                System.out.println("One more time!");
            } else {
                again = false;
            }
        } while (again);

        System.out.println("");
        
        
        
        
        
        
        System.out.println("===4===");
        StringBuilder aa = new StringBuilder();
        String b = "To be or not to be";
        String[] c = b.split(" ");
         
        for (int i = 0; i < c.length; i++) {
            StringBuilder cc = new StringBuilder(c[i]+" ");
            aa.append(cc.reverse());
        }
        System.out.println(aa);
        
    
        
        
        
        
        
        
        

        again = true;

        do {

            System.out.println("again?( y / other )");
            String ag = sc.next();
            if (ag.equals("y")) {
                System.out.println("One more time!");
            } else {
                again = false;
            }
        } while (again);

    }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值