File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Unit06/src/unit06/Actividad24_Aplicacion Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ package unit06 .Actividad24_Aplicacion ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ /*
6
+ Implementar un sencillo editor de texto que, una vez que se ha insertado el texto,
7
+ permita reemplazar todas las ocurrencias de una palabra por otra.
8
+ Para salir escribirá la palabra "salir".
9
+ */
10
+ public class Actividad24 {
11
+ public static void main (String [] args ) {
12
+ Scanner sc = new Scanner (System .in );
13
+ String entradaUsuario = "" ;
14
+ String texto ;
15
+
16
+ // Pedimos el texto
17
+ System .out .print ("Introduce un texto: " );
18
+ texto = sc .nextLine ();
19
+
20
+ // Mostramos el texto
21
+ System .out .println ("Texto introducido: \n " + texto );
22
+
23
+ // Pedimos la palabra a buscar
24
+ while (!entradaUsuario .equals ("!q" )) {
25
+ System .out .println ("Para salir escribe \" !q\" " );
26
+ System .out .print ("Introduce la palabra a buscar: " );
27
+ entradaUsuario = sc .nextLine ();
28
+ if (!entradaUsuario .equals ("salir" )) {
29
+ // Pedimos la palabra a reemplazar
30
+ System .out .print ("Introduce la palabra a reemplazar: " );
31
+ String palabraReemplazar = sc .nextLine ();
32
+ // Reemplazamos la palabra
33
+ texto = texto .replaceAll (entradaUsuario , palabraReemplazar );
34
+ // Mostramos el texto
35
+ System .out .println ("Texto modificado: \n " + texto );
36
+ }
37
+ }
38
+
39
+
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments