zoukankan      html  css  js  c++  java
  • 第13周作业集

    一.题目1

    创建两个线性表,分别存储{“chen”,“wang”,“liu”,“zhang”}和{“chen”,“hu”,“zhang”},求这两个线性表的交集和并集。

    package ccut;

    import java.util.HashSet;

    public class Text1 {

    public static void main(String[] args) {
    HashSet<String> a=new HashSet<String>();
    HashSet<String> b=new HashSet<String>();
    HashSet<String> X=new HashSet<String>();
    HashSet<String> U=new HashSet<String>();
    a.add("chen");
    a.add("wang");
    a.add("liu");
    a.add("zhang");
    b.add("chen");
    b.add("hu");
    b.add("zhang");
    X.addAll(a);
    X.retainAll(b);
    System.out.println("a与b的交集是"+X);
    U.addAll(a);
    U.addAll(b);
    System.out.println("a与b的并集是"+U);
    }

    }

      

    题目2

    编写一个应用程序,输入一个字符串,该串至少由数字、大写字母和小写字母三种字符中的一种构成,如“123”、“a23”、“56aD”、“DLd”、“wq”、“SSS”、“4NA20”,对输入内容进行分析,统计每一种字符的个数,并将该个数和每种字符分别输出显示。如:输入内容为“34Ah5yWj”,则输出结果为:数字——共3个,分别为3,4,5;小写字母——共3个,分别为h,y,j;大写字母——共2个,分别为A,W。

    package ccut;
    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    public class text {
    
    	public static void main(String[] args) {
    		System.out.println("请输入一个字符串");
    	Scanner re=new Scanner(System.in);
    	String s=re.nextLine();
    	String regex="[A-Za-z0-9]";
    	ArrayList<String> a1=new ArrayList<String>();
    	ArrayList<String> a2=new ArrayList<String>();
    	ArrayList<String> a3=new ArrayList<String>();
    	int num=0,daxie=0,xiaoxie=0;
    		for(int i=0;i<s.length();i++) {
    			String test=s.substring(i, i+1);
    			if(test.matches("[A-Z]"))
    					{
    				daxie++;
    				a1.add(test);
    					}
    			if(test.matches("[a-z]"))
    					{
    				xiaoxie++;
    				a2.add(test);
    					}
    			if(test.matches("[0-9]"))
    					{
    				num++;
    				a3.add(test);
    					}
    		}
    		System.out.println("大写字母有"+daxie+"个,分别是"+a1);
    		System.out.println("小写字母有"+xiaoxie+"个,分别是"+a2);
    		System.out.println("数字"+num+"个,分别是"+a3);
    		}
    
    
    }

     

  • 相关阅读:
    《C# to IL》第一章 IL入门
    multiple users to one ec2 instance setup
    Route53 health check与 Cloudwatch alarm 没法绑定
    rsync aws ec2 pem
    通过jvm 查看死锁
    wait, notify 使用清晰讲解
    for aws associate exam
    docker 容器不能联网
    本地运行aws lambda credential 配置 (missing credential config error)
    Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
  • 原文地址:https://www.cnblogs.com/guoxiang19/p/11967951.html
Copyright © 2011-2022 走看看