Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class sa
- {
- public static void main () throws IOException
- {
- int count =0;
- int count1=0;
- BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
- System.out.println ("Enter a sentence");
- String sent = br.readLine();
- String sent1 = sent + " ";
- int l = sent1.length();
- for (int a =0; a<l; a++)
- {
- if (sent1.charAt(a) == ' ')
- {
- count ++;
- }
- }
- String sentarr[] = new String[count];
- int p = 0;
- for (int c=0; c<l; c++)
- {
- char x= sent1.charAt(c);
- if (x == ' ')
- {
- String s2 = sent1.substring(p, c);
- sentarr[count1] = s2;
- count1++;
- p = c + 1;
- }
- }
- System.out.println ("Number of words =" + count);
- for (int d=0; d<count; d++)
- {
- System.out.println ("At index number" + d + " word is " + sentarr[d]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement