CamelCase in java

There is a sequence of words in camelCase as a string of letters, s , having the following properties:

  • It is a concatenation of one or more words consisting of English letters.
  • All letters in the first word are lowercase.
  • For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.

Given s , determine the number of words in s.

s = oneTwoThree There are 3 words in the string: “one”, “Two”, “Three”.

Input Format A single line containing string .

Output Format A single integer which is the total number of words in the string


  • 1 <= length of s <= 105

Sample Input


Sample Output



String contains five words:

  1. save
  2. Changes
  3. In
  4. The
  5. Editor

Solution of CamelCase in java:–

import java.util.*;
import java.lang.*;

public class Main
	public static void main (String[] args) throws java.lang.Exception
		//your code here
      Scanner sc = new Scanner(;
      String str =;
      int count=1;
      for(int i=0;i<str.length();i++)
          char ch=str.charAt(i);
          if(ch>='A' && ch<='Z')

Add a Comment

Your email address will not be published. Required fields are marked *