Kimes

Untitled

Oct 27th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Test2 {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner in = new Scanner(System.in);
  9.        
  10.         System.out.print("Ile licz musisz wylosować? ");
  11.         int k = in.nextInt();
  12.        
  13.         System.out.print("Jaka jest największa liczba? ");
  14.         int n = in.nextInt();
  15.        
  16.         int[] numbers = new int[n];
  17.         for (int i = 0; i < numbers.length; i++){
  18.             numbers[i] = i + 1;
  19.         }
  20.         int[] result = new int[k];
  21.         for (int i = 0; i <result.length; i++){
  22.             int r = (int) (Math.random() * n);
  23.             result[i] = numbers[r];
  24.             numbers[r] = numbers[n - 1];
  25.             n--;
  26.         }
  27.        
  28.         Arrays.sort(result);
  29.         System.out.println("Postaw na następujące liczby. Dzięki nim zdobędziesz bogactwo!");
  30.         for (int r : result)
  31.             System.out.println(r); 
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment