Java String Instance Practice Example #1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package edu.handong.csee.java.string; 
 
public class FamilyNamePrinter{
    private String[] stringNames; 
    private String[] familyNames;
     
    public void printFamilyNames(){
        for(String name: familyNames){
            if(name == null){
                System.out.print(""); 
            }else{
                System.out.println(name);
            }
        }
    }
    public FamilyNamePrinter(String names){
        
       stringNames = names.split(",");
       familyNames = new String[stringNames.length];
       int i=0
       for(String name: stringNames)
         familyNames[i++= name.trim().split(" ")[1]; 
    }
 
    public static void main (String[] args) {
        String myString = args[0]; 
        FamilyNamePrinter myFamily = new FamilyNamePrinter(myString); 
        myFamily.printFamilyNames();     
    }
}
cs

 

+ Recent posts