-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringsExercises.java
More file actions
39 lines (34 loc) · 1.41 KB
/
Copy pathstringsExercises.java
File metadata and controls
39 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package Strings;
/*
Clase 34 - Ejercicios: Strings
Vídeo: https://youtu.be/JOAqpdM36wI?t=9838
*/
import java.util.Locale;
public class stringsExercises {
public static void main(String[] args) {
// 1. Concatena dos cadenas de texto.
String a = "Wiky";
System.out.println(a + " " + "Ospina");
// 2. Muestra la longitud de una cadena de texto.
System.out.println(a.length());
// 3. Muestra el primer y último carácter de un string.
System.out.println(a.charAt(0));
System.out.println(a.charAt(3));
// 4. Convierte a mayúsculas y minúsculas un string.
System.out.println(a.toUpperCase());
System.out.println(a.toLowerCase());
// 5. Comprueba si una cadena de texto contiene una palabra concreta.
System.out.println(a.contains("y"));
// 6. Formatea un string con un entero.
System.out.println("Wiky".replace("Wiky", "7"));
// 7. Elimina los espacios en blanco al principio y final de un string.
System.out.println(a.trim());
// 8. Sustituye todos los espacios en blanco de un string por un guión (-).
System.out.println(a.trim());
// 9. Comprueba si dos strings son iguales.
String b = "Wiky";
System.out.println(a.equals(b));
// 10. Comprueba si dos strings tienen la misma longitud.
System.out.println(b.length() == a.length());
}
}