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) throws java.lang.Exception
  11. {
  12.  
  13. System.out.println("Hola ingresa una frase");
  14. String frase= "esta frase";
  15. System.out.println("Ahora ingresa la palabra a suplir");
  16. String palabrai="frase";
  17. System.out.println("Finalmente ingresa por cual palabra necesitas cambiar");
  18. String sustituir="Frase";
  19. String[] arreglofrase=frase.split(" ");
  20. String vacio="";
  21. for(int x=0;x<arreglofrase.length;x++){
  22. if (arreglofrase[x].equals(palabrai))
  23. {
  24. arreglofrase[x]=sustituir;
  25. System.out.println(Arrays.toString(arreglofrase).replaceAll("\\[|\\]|\\s", "").replaceAll("\\,", " "));
  26. }
  27. }
  28. }
  29. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
Hola ingresa una frase
Ahora ingresa la palabra a suplir
Finalmente ingresa por cual palabra necesitas cambiar
esta Frase