Camel Case 4

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
    
        // Keep reading until EOF (no more lines)
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            lines.add(line);
        }
        for (String s : lines) {
            System.out.println(createOrSplitCamelCaseMethod(s));
        }
    }
    
    public static String createOrSplitCamelCaseMethod(String str) {
        String [] strArr = str.split(";");
        String finalStr = "";
        int j = 0;
        if(strArr[0].equals("S")){
            if(strArr[1].equals("M") || strArr[1].equals("V")|| strArr[1].equals("C")){
                strArr[2] = strArr[2].replace("()", "");
               for(int i =0; i< strArr[2].length(); i ++){
                       if (strArr[1].equals("C")) {
                           if(i ==0)
                            continue;
                       }
                    if(Character.isUpperCase(strArr[2].charAt(i)) && j ==0){
                            finalStr = strArr[2].substring(j, i);
                            j = i;
                    }else if(Character.isUpperCase(strArr[2].charAt(i)) && j !=0) {
                        finalStr = finalStr + " " + strArr[2].substring(j, i);
                        j = i;
                    }else if(i == strArr[2].length()-1) {
                        finalStr = finalStr + " " + strArr[2].substring(j);
                    }
                }
                finalStr = finalStr.toLowerCase();
            }
        }else if(strArr[0].equals("C")){
           String strArr3 [] = strArr[2].split(" ");
           for(int i =0; i < strArr3.length; i ++){
            if(i ==0 && !strArr[1].equals("C")){
                finalStr = strArr3[0];
            }else{
                finalStr = finalStr + Character.toUpperCase(strArr3[i].charAt(0));
                finalStr = finalStr + strArr3[i].substring(1);
            }
           } 
            if(strArr[1].equals("M")){  
                finalStr = finalStr + "()";    
            }
        }  
        return finalStr;
    }
    

    }