Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/12/2016, 22:59
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: Verificar si un string tiene numeros consecutivos

Aqui tienes que te puede ayudar:

Código Java:
Ver original
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class NConsecutivos
  4. {
  5. private static int numeros[] = new int[3];
  6.  
  7. public static boolean probarConsecutivos(int arreglo[])
  8. {
  9.  
  10. Arrays.sort(arreglo);
  11. for(int i = 1; i < arreglo.length; i++)
  12. {
  13. if((arreglo[i] - 1) != arreglo[i - 1])   
  14. {
  15. return false;
  16. }
  17. }
  18.  
  19. return true;
  20.  
  21.  
  22. }
  23.  
  24. public static boolean probarConsecutivos(int uno, int dos, int tres)
  25. {
  26. int num[] = new int[3];
  27. num[0] = uno;
  28. num[1] = dos;
  29. num[2] = tres;
  30.  
  31. return probarConsecutivos(num);
  32. }
  33.  
  34. public static void main(String args[])
  35. {
  36.  
  37.  
  38. Scanner entrada = new Scanner(System.in);
  39. int uno;
  40. int dos;
  41. int tres;
  42.  
  43. System.out.print("Dame el primer numero: ");
  44. uno = entrada.nextInt();
  45. System.out.print("Dame el segundo numero: ");
  46. dos = entrada.nextInt();
  47. System.out.print("Dame el tercer numero: ");
  48. tres = entrada.nextInt();
  49.  
  50. if(probarConsecutivos(uno, dos, tres))
  51. {
  52. System.out.println("los numeros son consecutivos!");
  53. }else
  54. {
  55. System.out.println("los no numeros son consecutivos!");
  56. }
  57. }
  58. }