Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. 6)
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class handon26 {
  7. public static void main(String[] args) {
  8. Scanner a = new Scanner(System.in);
  9. String b =a.nextLine();
  10. String d = camelCase(b);
  11.  
  12. ArrayList<String> c = new ArrayList<>(Arrays.asList(d.split(" ")));
  13. System.out.println(b+" ("+b.length()+" Character)");
  14. for (String e:c) {
  15. System.out.print(e);
  16. }
  17. System.out.print(" ("+(b.length()-c.size()+1)+" Character)");
  18. }
  19. static String camelCase(String str)
  20. {
  21. char ch[] = str.toCharArray();
  22. for (int i = 0; i < str.length(); i++) {
  23. if (i == 0 && ch[i] != ' ' ||
  24. ch[i] != ' ' && ch[i - 1] == ' '||
  25. ch[i] != ' ' && ch[i - 1] == '.'||
  26. ch[i] != ' ' && ch[i - 1] == '?'||
  27. ch[i] != ' ' && ch[i - 1] == '!') {
  28. if (ch[i] >= 'a' && ch[i] <= 'z') {
  29. ch[i] = (char)(ch[i] - 'a' + 'A');
  30. }
  31. }
  32. else if (ch[i] >= 'A' && ch[i] <= 'Z')
  33. ch[i] = (char)(ch[i] + 'a' - 'A');
  34. }
  35. String st = new String(ch);
  36. return st;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement