Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 6)
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner;
- public class handon26 {
- public static void main(String[] args) {
- Scanner a = new Scanner(System.in);
- String b =a.nextLine();
- String d = camelCase(b);
- ArrayList<String> c = new ArrayList<>(Arrays.asList(d.split(" ")));
- System.out.println(b+" ("+b.length()+" Character)");
- for (String e:c) {
- System.out.print(e);
- }
- System.out.print(" ("+(b.length()-c.size()+1)+" Character)");
- }
- static String camelCase(String str)
- {
- char ch[] = str.toCharArray();
- for (int i = 0; i < str.length(); i++) {
- if (i == 0 && ch[i] != ' ' ||
- ch[i] != ' ' && ch[i - 1] == ' '||
- ch[i] != ' ' && ch[i - 1] == '.'||
- ch[i] != ' ' && ch[i - 1] == '?'||
- ch[i] != ' ' && ch[i - 1] == '!') {
- if (ch[i] >= 'a' && ch[i] <= 'z') {
- ch[i] = (char)(ch[i] - 'a' + 'A');
- }
- }
- else if (ch[i] >= 'A' && ch[i] <= 'Z')
- ch[i] = (char)(ch[i] + 'a' - 'A');
- }
- String st = new String(ch);
- return st;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement