fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String args[]){
  11. Scanner sc=new Scanner(System.in);
  12. //System.out.println("enter the message to be sent ");
  13. String data=sc.nextLine();
  14. String res=new String();
  15. String out=new String();
  16. data='F'+data+'F';
  17. for(int i=0;i<data.length();i++){
  18. if(data.charAt(i)=='F'&&i!=0&&i!=(data.length()-1))
  19. res=res+'E'+data.charAt(i);
  20. else if(data.charAt(i)=='E')
  21. res=res+'E'+data.charAt(i);
  22. else
  23. res=res+data.charAt(i);
  24. }
  25. System.out.println("the message transferred after byte stuff "+res);
  26. //System.out.println("sender message...");
  27. for(int i=1;i<res.length()-1;i++){
  28. if(res.charAt(i)=='D'||res.charAt(i)=='F')
  29. out=out+res.charAt(i);
  30. else if(res.charAt(i)=='E'&&res.charAt(i+1)=='E'){
  31. out=out+'E';
  32. i++;
  33. }
  34. else if(res.charAt(i)=='E'&&res.charAt(i+1)=='F'){
  35. out=out+'F';
  36. i++;
  37. }
  38. else
  39. out=out+res.charAt(i);
  40. }
  41. System.out.println("the destuffed message "+out);
  42. }
  43. }
  44.  
Success #stdin #stdout 0.06s 2184192KB
stdin
HARI
stdout
the message transferred after byte stuff FHARIF
the destuffed message HARI