forked from harambeisnotdead/java-carande
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cadena2.java
37 lines (28 loc) · 970 Bytes
/
cadena2.java
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
import java.util.Scanner;
class cadena2 {
public static void main(String[] args) {
String abc = "abcdefghijklmnopqrstuvwxyz";
String ABC09 = abc.toUpperCase()+"0123456789";
abc+=ABC09;
String resultado="";
int strInicio, strFinal;
Scanner scanner = new Scanner(System.in);
System.out.print("Introduce una string: ");
String palabra = scanner.nextLine()+" ";
//if (abc.indexOf(palabra.charAt(0))!=-1) {contador=1;}
for (int i=0;i<palabra.length();i++) {
char a = palabra.charAt(i);
char b = ' ';
if (i+1<palabra.length()) {b = palabra.charAt(i+1);}
if (abc.indexOf(a)!=-1) { //encontrar principio
strInicio=palabra.indexOf(palabra.charAt(b));
System.out.print(strInicio);
}
if ( abc.indexOf(a)!=-1 && b == ' ') { //encontar final
strFinal=palabra.indexOf(palabra.charAt(a));
System.out.print(strFinal);
}
}
System.out.println("");
}
}