Click here to Skip to main content
15,868,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
 write function and variable names in Camel Case.

string S, written in Camel Case. Find All The Words Contained In It.

Complete the given function. print the answer.

Example 1

Input
IAmAJavaProgrammer

Output
I
Am
A
Java
Programmer

Explanation

separate each word and print them in a new line.


What I have tried:

import java.io.*;
import java.util.*;
public class Main {
  
  public static void solution(String str) {

	  char s = 'A';
	  for(int i=0; i<str.length(); i++){
		  if(str.charAt(i)<s){
			  char[] a = str.split((String)'s');
				  System.out.print(a);
		  }
	  }
    
  }

  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    String str = scn.next();
    solution(str);
  }
}
Posted
Updated 8-Feb-23 0:43am

1 solution

You just need to check the case of each character. An upper case character signifies the start of a new word. So starting from the beginning of the string copy the first upper case character to a new string. Then for each following character, if it is lower case, copy it to the new string. When you find an upper case character, print the current "new" string, and reset to start the next sequence.

You may need to use the Character (Java Platform SE 7 )[^] class.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900