0
String matching
import java.io.*; import java.util.*; public class regex { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s =scan.nextLine(); char c =' ' ; String p =""; int count =0; for(int i=0; i<s.length();i++) { c=s.charAt(i); if((c!=' ')&&(c!=',')&&(c!='.')&&(c!='`')&&(c!='?')&&(c!='_')&&(c!='@')) { p=p+c;} else { System.out.println(p); count++; p=""; } } System.out.println(count) ; scan.close(); } }
4 Respostas
+ 2
So, do you have a programming question related to the above problem? I see you already have the solution.
0
Given a string, s, 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.
Input formAT
A single string, s
s 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
boy
isn
t
he
0
standard input
Hello, thanks for attempting this problem! Hope it will help you to learn java! Good luck and have a nice day!
expected output
21
Hello
thanks
for
attempting
this
problem
Hope
it
will
help
you
to
learn
java
Good
luck
and
have
a
nice
day
my output
Hello
thanks
for
attempting
this
problem!
Hope
it
will
help
you
to
learn
java!
Good
luck
and
have
a
nice
21
0
My solution is not correct...!!