Java Week 13 job set

I, entitled 1

Create two linear form, are stored { "chen", "wang", "liu", "zhang"} and { "chen", "hu", "zhang"}, intersection of these two tables and linear and set.

Second, the source code

package thirteen;
import java.util.ArrayList;
import java.util.HashSet;
public class Test1 {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ArrayList<String> s1=new ArrayList<String>();
        s1.add("cheng");
        s1.add("wang");
        s1.add("liu");
        s1.add("zhang");
        System.out.println ("A linear form:" + S1); 
        the ArrayList <String> S2 = new new the ArrayList <String> (); 
        s2.add ( "Cheng ' ); 
        s2.add ( " Hu " ); 
        s2.add ( " Zhang " ) ; 
        System.out.println ( "linear table II:" + S2); 
        the ArrayList <String> S3 = new new the ArrayList <String> (); 
        s3.addAll (S1); 
        s3.retainAll (S2); // delete the two set different elements 
        System.out.println ( "the intersection of two linear form:" + S3); 
        the ArrayList <String>s4=new ArrayList<String>(); 
        s4.addAll (S1); 
        s4.addAll (S2); 
        HashSet <String> SET = new new HashSet <String> (); // deduplication 
        set.addAll (S4); 
        System.out.println ( " linear and two sets of tables: "+ sET); 
    } 
}

Third, the operating results

I, entitled 2

Writing an application, enter a string, the string of at least a digital, three kinds of uppercase and lowercase characters is configured as "123", "a23", "56aD", "DLd", "wq" , "SSS", "4NA20", analyzes the content of the input, count the number of each of the characters, and each character and the number of display outputs. Such as: the input content is "34Ah5yWj", then the output is: Digital - a total of three, are 3,4,5; lowercase - a total of three, respectively, h, y, j; capital letters - co 2, respectively, A, W.

Second, the source code

package thirteen;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Test2 {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub{
        int letter=0,lowercase=0,digit=0;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a string, the string of at least a number A uppercase and lowercase characters constituting three kinds, such as" 123 "," A23 "," 56aD "" ); 
        String STR = sc.nextLine (); 
        the HashMap <Integer, Character> h1 of = new new the HashMap <Integer, Character> (); 
        the HashMap <Integer, Character> H2 = new new the HashMap <Integer, Character> (); 
        the HashMap <Integer, Character> H3 = new new the HashMap <Integer, Character > ();
         char [] = CH str.toCharArray ();
         for ( int I = 0; I <ch.length; I ++) { // determines whether uppercase letters 
            iF ( 'A' <CH [I] && CH [I ] < 'Z ' ) {
                Letter ++ ; 
                h1.put (I, CH [I]); 
            } 
            IF ( 'A' <CH [I] && CH [I] < 'Z') { // determines whether lowercase letter 
                lowercase ++ ; 
                h2.put (I , CH [I]); 
            } 
            iF (by Character.isDigit (CH [I])) { // determines whether the number 
                digit for ++ ; 
                h3.put (I, CH [I]); 
            } 
        } 
        of System.out.print ( " capital letter - co "+ letter +", respectively, as " );
         // the Set method of the Map, each capital letter read 
        the Set setl = h1.entrySet ();
        Iterator iterator1=set1.iterator ();
         the while (iterator1.hasNext ()) { 
            of Map.Entry MAP1 = (of Map.Entry) iterator1.next (); 
            of System.out.print ( "" + map1.getValue ()); 
        } 
        the System. Out.println ( "" );
         // the Set method of the Map, each read lowercase 
        System.out.print ( "lowercase - co" + lowercase + ", respectively, as" ); 
        the Set SET2 = h2.entrySet (); 
        the Iterator a iterator2 = set2.iterator ();
         the while (iterator2.hasNext ()) { 
            of Map.Entry MAP2 = (of Map.Entry) iterator2.next ();
            Of System.out.print ( "" +map2.getValue ()); 
        } 
        System.out.println (); 
        // the Set method of the Map, each digital read 
        System.out.print ( "Digital - co" + digit + ", respectively, as" ); 
        SET3 SET = h3.entrySet (); 
        the Iterator iterator3 = set3.iterator ();
         the while (iterator3.hasNext ()) { 
            of Map.Entry MAP3 = (of Map.Entry) iterator3.next (); 
            of System.out.print ( " "+ map3.getValue ()); 
        } 
    } 
}

Third, the operating results

Guess you like

Origin www.cnblogs.com/jingxueyan/p/11966010.html