Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class task1 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //Create a scanner object
- Scanner input = new Scanner(System.in);
- //Prompt user's input
- System.out.println("Enter strings (use a space to separate them; hit enter to finish) : ");
- String str = input.nextLine();
- // use split to divide the string into different words cutting by " "
- String [] wordsArray = str.trim().split(" ");
- System.out.println("The length of string is " + wordsArray.length);
- for (int i = 0; i < wordsArray.length; i++) {
- char[] eachLetterinArray = wordsArray[i].toCharArray();
- int count = 0;
- for (int j = 0; j < eachLetterinArray.length; j++) {
- if ((eachLetterinArray[j] + 'a' - 97 >= 65 && eachLetterinArray[j] + 'a' - 97 <= 90)
- || (eachLetterinArray[j] + 'a' - 97 >= 97 && eachLetterinArray[j] + 'a' - 97 <= 122)) {
- count++;
- }
- }
- System.out.println(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement