Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TASK 1
- import java.util.Scanner;
- public class Task1 {
- public static void main(String[] args) {
- int fact = 1;
- long p = 1 ;
- int z = 1;
- int c = 1;
- Scanner input = new Scanner(System.in);
- int n = input.nextInt();
- int k = input.nextInt();
- input.close();
- for(int i = 1; i <= k; i ++)
- {
- p =(long) (p*(n - k + i));
- }
- System.out.println(p);
- while(z <= k)
- {
- fact = fact * z;
- z++;
- }
- System.out.println(fact);
- c = (int) (p / fact);
- System.out.println(c);
- }
- }
- ///TASK2
- import java.util.Scanner;
- public class Task2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter from how many numbers we extract: ");
- int n = input.nextInt();
- System.out.println("Enter how many numbers we extract:");
- int k = input.nextInt();
- int[] arr = new int[k];
- input.close();
- for(int i = 0; i < k; i++)
- {
- int random = (int) (Math.random() * n) + 1;
- for (int j = 0; j < i; j++ )
- {
- if (arr[j] == random)
- {
- random = (int) (Math.random() * n) + 1;
- j = -1;
- }
- }
- arr[i] = random;
- }
- for(int i = 0; i < k; i ++)
- System.out.println(arr[i] + " ");
- }
- }
- ///// TASK4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement