Advertisement
joseleonweb

Untitled

Aug 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. public class TresBucles {
  2.   public static void main (String[] args) {
  3.  
  4.   int[] array = {2, 6, 10, 7, 9, 5, 4, 2, 5, 1, 7, 5, 2};
  5.   int i = 0;
  6.  
  7.   //BUCLE 1
  8.   for (i = 0; i < array.length ; i++) {
  9.     int suma = array[i] + array[i + 1];
  10.     System.out.println(suma);
  11.   }
  12.  
  13.   //BUCLE 2
  14.   int compta = 0;
  15.   i = 0;
  16.   while (compta < 2) {
  17.     if (array[i] == 7) {
  18.       compta++;
  19.     }
  20.     i++;
  21.   }
  22.   System.out.println(compta);
  23.  
  24.   //BUCLE 3
  25.   int acum = 0;
  26.   i = 0;
  27.   while ((acum < 20)&&(i < array.length)) {
  28.     acum = acum + array[i];
  29.     i++;
  30.   }
  31.   System.out.println(acum);
  32.  
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement