Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. //TASK 1
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class Task1 {
  6.  
  7.  
  8. public static void main(String[] args) {
  9.  
  10. int fact = 1;
  11. long p = 1 ;
  12. int z = 1;
  13. int c = 1;
  14. Scanner input = new Scanner(System.in);
  15. int n = input.nextInt();
  16. int k = input.nextInt();
  17. input.close();
  18. for(int i = 1; i <= k; i ++)
  19. {
  20. p =(long) (p*(n - k + i));
  21. }
  22. System.out.println(p);
  23.  
  24. while(z <= k)
  25. {
  26. fact = fact * z;
  27. z++;
  28. }
  29. System.out.println(fact);
  30. c = (int) (p / fact);
  31.  
  32. System.out.println(c);
  33.  
  34. }
  35.  
  36.  
  37. }
  38. ///TASK2
  39. import java.util.Scanner;
  40.  
  41. public class Task2 {
  42.  
  43. public static void main(String[] args) {
  44.  
  45. Scanner input = new Scanner(System.in);
  46. System.out.println("Enter from how many numbers we extract: ");
  47. int n = input.nextInt();
  48. System.out.println("Enter how many numbers we extract:");
  49. int k = input.nextInt();
  50. int[] arr = new int[k];
  51. input.close();
  52.  
  53. for(int i = 0; i < k; i++)
  54. {
  55. int random = (int) (Math.random() * n) + 1;
  56.  
  57. for (int j = 0; j < i; j++ )
  58. {
  59. if (arr[j] == random)
  60. {
  61. random = (int) (Math.random() * n) + 1;
  62. j = -1;
  63. }
  64.  
  65. }
  66. arr[i] = random;
  67.  
  68. }
  69. for(int i = 0; i < k; i ++)
  70. System.out.println(arr[i] + " ");
  71. }
  72. }
  73.  
  74. ///// TASK4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement