Duda con código (palíndromos)
Publicado por Armando (1 intervención) el 15/11/2018 21:06:46
Hola, buen día, llevo apenas un mes en el mundo de la programación, esta pagina me ha servido mucho para cursos y apoyo en resolución de problemas.
Estoy realizando el código de un problema pero a la hora de correrlo me marca errores (no imprime lo que deseo). Les dejo el código para que alguien bondadoso me eche la mano.
Muchas gracias!!
(Palindromes) A palindrome is a sequence of characters that reads the same backward as for- ward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.
Estoy realizando el código de un problema pero a la hora de correrlo me marca errores (no imprime lo que deseo). Les dejo el código para que alguien bondadoso me eche la mano.
Muchas gracias!!
(Palindromes) A palindrome is a sequence of characters that reads the same backward as for- ward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.
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
package palindromos;
import javax.swing.JOptionPane;
public class Palindromos {
public static void main(String[] args) {
int numero;
int a, b, c, d, e;
numero = Integer.parseInt(JOptionPane.showInputDialog("Digite un numero de 5 digitos"));
a = numero / 10000;
b = numero / 1000 % 10;
c = numero / 100 % 10;
d = numero / 10 % 10;
e = numero % 10;
if (a == e && b == d) {
JOptionPane.showMessageDialog(null, "El numero es un palindromo");
}
while (a != e && b != d) {
JOptionPane.showMessageDialog(null, "El numero no es un palindromo");
if (numero > 99999) {
JOptionPane.showMessageDialog(null, "No es un numero de 5 diitos");
} else if (numero < 10000) {
JOptionPane.showMessageDialog(null, "No es un numero de 5 diitos");
}
numero = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite otro numero"));
}
}
}
Valora esta pregunta
0