Advertisement
Guest User

Untitled

a guest
May 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication6;
  7.  
  8. /**
  9. *
  10. * @author Mihai
  11. */
  12. public class JavaApplication6 {
  13.  
  14. public static void main(String[] args) {
  15. muestraResultado(tomaArray());
  16. }
  17.  
  18. static int[] tomaArray() {
  19.  
  20. int[] num = new int[]{2, 1, 2, 2, 2, 5, 5, 1, 2, 5};
  21.  
  22. /*for (int i = 0; i < num.length; i++) {
  23. num[i] = (int) (Math.random() * 5);
  24. }*/
  25. return num;
  26. //return num;
  27. }
  28.  
  29. /*
  30. * @param args the command line arguments
  31. */
  32. static void muestraResultado(int[] a) {
  33. int i, max = 1, parcial = 1;
  34. System.out.print("El array devuelto es: [");
  35. for (i = 0; i < a.length - 1; i++) {
  36. System.out.print(a[i] + ", ");
  37.  
  38. if (a[i] == a[i + 1]) {
  39. parcial++;
  40. } else {
  41. parcial = 1;
  42. }
  43.  
  44. if (parcial > max) {
  45. max = parcial;
  46. }
  47.  
  48. }
  49.  
  50. System.out.println(a[i] + "]");
  51. System.out.println("Tamaño de la repeticion mas larga es: " + max);
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement