Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Targil24
  3. {
  4. public static String smarty(String tamlilim)
  5. {
  6. int i=0,WordsCount=0,d=0;
  7. String newstr="",temp="";
  8. tamlilim=tamlilim+" ";
  9.  
  10. while(i<=tamlilim.length()-1)
  11. {
  12. if(tamlilim.charAt(i)==' ')
  13. WordsCount++;
  14. i++;
  15. }
  16. String [] str = new String[WordsCount+1];
  17. i=0;
  18. while(i<=tamlilim.length()-1)
  19. {
  20. if(tamlilim.charAt(i)==' ')
  21. {
  22. str[d]=temp;
  23. temp="";
  24. d++;
  25. }
  26. else
  27. {
  28. temp=temp+tamlilim.charAt(i);
  29. }
  30. i++;
  31. }
  32. for(i=0;i<WordsCount;i++)
  33. {
  34. if(str[i].equals(str[i+1])==false)
  35. newstr=newstr+str[i]+" ";
  36.  
  37.  
  38. }
  39.  
  40.  
  41. return newstr;
  42. }
  43. {
  44. }
  45. static Scanner reader=new Scanner(System.in);
  46. public static void main(String[] args)
  47. {
  48. Scanner in= new Scanner (System.in);
  49. String a;
  50. System.out.println("הכנס משפט:");
  51. a=in.nextLine();
  52. System.out.print(smarty(a));
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement