Advertisement
joseleonweb

Untitled

Aug 26th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OmpleArrayTeclat {
  4.  
  5.   public static void main (String[] args) {
  6.  
  7.     Scanner lector = new Scanner(System.in);
  8.  
  9.     int[] array = new int[10];
  10.  
  11.     System.out.println("Es llegiran " + array.length + " valors enters.");
  12.     System.out.println("Pots escriure'n diversos en una sola línia.");
  13.  
  14.     int index = 0;
  15.     while (index < array.length) {
  16.       if (lector.hasNextInt()) {
  17.         array[index] = lector.nextInt();
  18.         index++;
  19.       } else {
  20.         lector.next();
  21.       }
  22.     }
  23.     lector.nextLine();
  24.  
  25.     System.out.println("La seqüència llegida és:");
  26.     for (int i = 0; i < array.length;i++) {
  27.       System.out.println(array[i]);
  28.     }
  29.   }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement