Skip to main content

Posts

Showing posts from December, 2017

Java String Tokens | Regex expression

Given a string,  , matching the regular expression  [A-Za-z !,?._'@]+ , split the string into  tokens . We define a token to be one or more consecutive English alphabetic letters. Then, print the number of tokens, followed by each token on a new line. Note:  You may find the  String.split  method helpful in completing this challenge. Input Format A single string,  . Constraints  is composed of  any  of the following: English alphabetic letters, blank spaces, exclamation points ( ! ), commas ( , ), question marks ( ? ), periods ( . ), underscores ( _ ), apostrophes ( ' ), and at symbols ( @ ). Output Format On the first line, print an integer,  , denoting the number of tokens in string   (they  do not  need to be unique). Next, print each of the   tokens on a new line in the same order as they appear in input string  . Sample Input He is a very very good boy, isn't he? Sample Output 10 He is a very very good

Java Anagrams

Two strings,   and  , are called anagrams if they contain all the same characters in the same frequencies. For example, the anagrams of  CAT  are  CAT ,  ACT ,  TAC ,  TCA ,  ATC , and  CTA . Complete the function in the editor. If   and   are case-insensitive anagrams, print "Anagrams"; otherwise, print "Not Anagrams" instead. Input Format The first line contains a string denoting  . The second line contains a string denoting  . Constraints Strings   and   consist of English alphabetic characters. The comparison should NOT be case sensitive. Output Format Print "Anagrams" if   and   are case-insensitive anagrams of each other; otherwise, print "Not Anagrams" instead. Sample Input 0 anagram margana Sample Output 0 Anagrams Explanation 0 Character Frequency:  anagram Frequency:  margana A  or  a 3 3 G  or  g 1 1 N  or  n 1 1 M  or  m 1 1 R  or  r 1 1 T