Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Collection
  4. {
  5.         private static Scanner scanner = new Scanner(System.in);
  6.        
  7.         public static void main(String[] args)
  8.         {
  9.             int dimension = dimensionCounter(scanner);
  10.             collectionFiller(scanner, dimension);
  11.             scanner.close();
  12.         }
  13.        
  14.         public static int dimensionCounter(Scanner scanner)
  15.         {
  16.             //Введение размерности массива чисел
  17.             System.out.print("Dimension: ");
  18.             int dimension = Integer.parseInt(scanner.nextLine());
  19.             System.out.printf("Enter dimension: %d \n", dimension);
  20.             return dimension;
  21.         }
  22.  
  23.         public static void collectionFiller(Scanner scanner, int dimension)
  24.         {
  25.             int[] collection;
  26.             collection = new int[dimension];
  27.             //Цикл ввода элементов массива
  28.             int i = 0;
  29.             while (i < dimension)
  30.             {
  31.                 System.out.print("Enter char "+ (i+1) +":");
  32.                 collection[i] = scanner.nextInt();
  33.                 System.out.printf("Char entered: %d \n",  collection[i]);
  34.                 i++;
  35.             }
  36.         }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement