CamelCase Solution in Java | HackerRank | CamelCase HackerRank Solution | CamelCase Solution Java HackerRank | CamelCase Solution


CamelCase Solution in Java| HackerRank | CamelCase HackerRank Solution | CamelCase Solution HackerRank | CamelCase Solution


CamelCase Solution in Java


CamelCase Solution in Java

CamelCase HackerRank Solution in Java


Problem:

Alice wrote a sequence of words in CamelCase as a string of letters, , 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 , print the number of words in  on a new line.

For example, . There are  words in the string.

Function Description

Complete the camelcase function in the editor below. It must return the integer number of words in the input string.

camelcase has the following parameter(s):

  • s: the string to analyze

Input Format

A single line containing string .

Constraints

Output Format

Print the number of words in string .

Sample Input

saveChangesInTheEditor

Sample Output

5

Explanation

String  contains five words:

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

Thus, we print  on a new line.

CamelCase HackerRank Solution in Java

CamelCase Solution 

import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; public class Solution { // Complete the camelcase function below. static int camelcase(String s) { return (s.length() - s.replaceAll("[A-Z]", "").length() + 1); } private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); String s = scanner.nextLine(); int result = camelcase(s); bufferedWriter.write(String.valueOf(result)); bufferedWriter.newLine(); bufferedWriter.close(); scanner.close(); } }

Post a Comment

0 Comments