Advanced Java questions -4

August 24, 2011 ・2comments

A program which will accept three sentences (one sentence per line) and print the words having Initial Caps within the sentences. Below is an example.

Here is an example. If the below three sentences are given to the program as input,

This is a Program
Coding test of Initial Caps
the program Will Test You

Then, the output would look like:

This
Program
Coding
Initial
Caps
Will
Test
You

Solution:
Pattern p = Pattern.compile("^[A-Z]");


2 comments

  1. This code works fine but if i input
    My Name is Harry
    Helloo how aRe yOU
    What u DoINg

    the result is

    My
    Name
    Harry
    Helloo
    aRe
    yOU
    What
    DoNIg

    But according the question only words with intial caps sholud be displayed in output but aRe is not having intial caps as a is small

    ReplyDelete
  2. @Anonymous

    I think you are wrong. because output is:

    My
    Name
    Harry
    Helloo
    What
    DoINg

    ReplyDelete

If you can't comment, try using Chrome instead.