Tuesday, April 21, 2020

Title

Title (100 Marks)

You just need to take string input and checks whether all the case-based characters in the string following non-casebased letters. Non-casebased letters are uppercase and all other case-based characters are lowercase.

Input Format
You will be given a function with string as single argument. 

Constraints
1 <= |S| <= 10^4

Output Format
You need to return the String either "True" or "False". 

Sample TestCase 1
Input
This Is String Example
Output
True
Solution:













import java.io.*;
import java.util.*;
public class CandidateCode {
      public static void main(String args[] ) throws Exception {
          Scanner sc = new Scanner(System.in);
          String s1 = sc.nextLine();
          StringBuffer s2 = new StringBuffer();

        String arr[] = s1.split(" ");
        for(int i=0; i<arr.length; i++)
        {
            s2.append(arr[i].substring(0,1).toUpperCase() + arr[i].substring(1)+" ");
        }
       String str = s2.toString();
       if(s1.equals(str.trim()))
             System.out.print("True");
        else
             System.out.print("False");
       }
}

No comments:

Post a Comment