You are viewing a single comment's thread. Return to all comments →
can anyone tell me whats wrong here?#Java
import java.io.; import java.util.;
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 scanner =new Scanner(System.in); while(scanner.hasNextLine()){ String input=scanner.nextLine(); //System.out.println(input); char dec1=input.charAt(0); char dec2=input.charAt(2); int last=input.length()-1; char lastIndex=input.charAt(last); //int lastBefore=last-1; StringBuilder result= new StringBuilder(); if(dec1=='S'){ for(int i=4;i<input.length();i++){ char currentChar = input.charAt(i); if(Character.isUpperCase(currentChar) && i>0){ result.append(" "); } result.append(currentChar); } if(dec2=='M' && lastIndex==')'){ result.delete(result.length()-2, result.length()); result.toString().toLowerCase(); System.out.println(result); }else if(dec2=='V' && result.toString().contains(" ")){ int index= result.indexOf(" "); if(index<result.length()){ //setCharAt(index, character) result.setCharAt(index+1,Character.toLowerCase(result.charAt(index+1))); } System.out.println(result.toString()); }else if(dec2=='C' && result.toString().contains(" ")){ if(result.charAt(0)==' '){ result.deleteCharAt(0); System.out.println(result.toString().toLowerCase()); }else{ System.out.println(result.toString().toLowerCase()); } } }else{ StringBuilder newBuild=new StringBuilder(input); if(dec2=='V' && newBuild.toString().contains(" ")){ newBuild.delete(0,4); for(int i=0; i<newBuild.length();i++){ if(newBuild.charAt(i)==' ' && Character.isLowerCase(newBuild.charAt(i+1))){ newBuild.deleteCharAt(i); newBuild.setCharAt(i,Character.toUpperCase(newBuild.charAt(i))); } } System.out.println(newBuild.toString()); }else if(dec2=='C'){ newBuild.delete(0,4); if(Character.isLowerCase(newBuild.charAt(0))){ newBuild.setCharAt(0,Character.toUpperCase(newBuild.charAt(0))); } for(int i=0; i<newBuild.length()-1;i++){ // char ch=newBuild.charAt(i); if(newBuild.charAt(i)==' ' && Character.isLowerCase(newBuild.charAt(i+1))){ newBuild.deleteCharAt(i); newBuild.setCharAt(i, Character.toUpperCase(newBuild.charAt(i))); } } System.out.println(newBuild.toString()); }else if(dec2=='M'&&newBuild.toString().contains(" ")){ newBuild.delete(0,4); for(int i=0; i<newBuild.length()-1; i++){ if(newBuild.charAt(i)==' ' && Character.isLowerCase(newBuild.charAt(i+1))){ newBuild.deleteCharAt(i); newBuild.setCharAt(i, Character.toUpperCase(newBuild.charAt(i))); } }newBuild.append("()"); System.out.println(newBuild.toString()); } } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Camel Case 4
You are viewing a single comment's thread. Return to all comments →
can anyone tell me whats wrong here?#Java
import java.io.; import java.util.;
public class Solution {