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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); String[] strLiStrings = str.split("\\s+"); for(String subString : strLiStrings) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(Character.toUpperCase(subString.charAt(0))); char pre = ' '; char now = ' '; for(int i = 0; i < subString.length(); i++) { now = subString.charAt(i); if(i != 0) { if(pre == ' ' && now == ' ') { continue; } else { stringBuffer.append(now); } } pre = now; } pre = ' '; now = ' '; for(int i = 0; i < stringBuffer.length(); i++) { now = stringBuffer.charAt(i); if(i != 0) { if(Character.isDigit(pre) && Character.isAlphabetic(now) || Character.isAlphabetic(pre) && Character.isDigit(now)) { stringBuffer.insert(i, '_'); } } pre = now; } System.out.print(stringBuffer); System.out.print(' '); } scan.close(); } }
|