Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // This code will generate the odds of a lottery win
  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. System.out.println("The odds are:");
  32. System.out.println(c);
  33.  
  34. }
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement