Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import java.io.*;
  2. class sa
  3. {
  4. public void main ()throws Exception, IOException
  5. {
  6. int count =0;
  7. int count1=0;
  8. BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
  9. System.out.println ("Enter a sentence");
  10.  
  11. String sent = br.readLine();
  12.  
  13. String sent1 = sent + " ";
  14. int l = sent1.length();
  15. for (int a =0; a<l; a++)
  16. {
  17. if (sent1.charAt(a) == ' ')
  18. {
  19. count ++;
  20. }
  21. }
  22. String sentarr[] = new String[count];
  23.  
  24.  
  25.  
  26. for (int c=0; c<l; c++)
  27. {
  28. char x= sent1.charAt(c);
  29. if (x != ' ')
  30. {
  31. sentarr[count1] = sentarr[count1] + x;
  32. }
  33. if (x == ' ')
  34. {
  35. count1++;
  36. }
  37. }
  38. System.out.println ("Number of words =" + count);
  39. for (int d=0; d<count; d++)
  40. {
  41. System.out.println ("At index number" + d + " word is " + sentarr[d]);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement