Skip to content

Commit 6771c55

Browse files
committed
Added Actividad24_Aplicacion - Unit06
1 parent eb3f8e3 commit 6771c55

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)