-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblema26.java
More file actions
49 lines (38 loc) · 1.39 KB
/
Copy pathProblema26.java
File metadata and controls
49 lines (38 loc) · 1.39 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
40
41
42
43
44
45
46
47
48
49
import acm.program.ConsoleProgram;
import java.util.StringTokenizer;
//PROBLEMA CON l amuestro de int con caracteres (no era asi)
public class Problema26 extends ConsoleProgram {
/* public void run() {
String prompt = readLine("Introduce un numero, con signo : ");
println(myReadInt(prompt));
return null;
}
public int myReadInt(String prompt) {
StringBuilder numRes = new StringBuilder();
// PUESTA DEL SIGNO
char[] fraseChar = prompt.toCharArray();
String signo = String.valueOf(fraseChar[0]);
numRes = numRes.append(signo);
StringTokenizer digit = new StringTokenizer(prompt.substring(1), "qwertuiopasdfghjklñzxcvbnm");
while (digit.hasMoreTokens()) {
String actualDigit = digit.nextToken();
if (isDigit(actualDigit)) {
numRes.append(actualDigit);
}
}
return Integer.parseInt(numRes.toString());
}
public boolean isDigit(String actualDigit) {
String[] numeros = {"0", "1", "2", "3", "4", "5", "6", "7","8", "9"};
for (int i = 0; i < numeros.length; i++) {
if (actualDigit.equals(numeros[i])) {
return false;
}
}
return true;
}
*/
public static void main (String[] args) {
new Problema26().start(args);
}
}