Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class task1 {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7.  
  8. //Create a scanner object
  9. Scanner input = new Scanner(System.in);
  10.  
  11. //Prompt user's input
  12. System.out.println("Enter strings (use a space to separate them; hit enter to finish) : ");
  13.  
  14. String str = input.nextLine();
  15.  
  16. // use split to divide the string into different words cutting by " "
  17. String [] wordsArray = str.trim().split(" ");
  18.  
  19. System.out.println("The length of string is " + wordsArray.length);
  20.  
  21. for (int i = 0; i < wordsArray.length; i++) {
  22. char[] eachLetterinArray = wordsArray[i].toCharArray();
  23. int count = 0;
  24. for (int j = 0; j < eachLetterinArray.length; j++) {
  25. if ((eachLetterinArray[j] + 'a' - 97 >= 65 && eachLetterinArray[j] + 'a' - 97 <= 90)
  26. || (eachLetterinArray[j] + 'a' - 97 >= 97 && eachLetterinArray[j] + 'a' - 97 <= 122)) {
  27.  
  28. count++;
  29. }
  30. }
  31. System.out.println(count);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement