Dido09

Toto

Nov 6th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class App{
  5.  
  6. public static void main(String []args){
  7.  
  8. Random rand = new Random();
  9. Scanner sc = new Scanner(System.in);
  10.  
  11. int[] nums = {0,0,0,0,0,0};
  12.  
  13. for(int i=0;i<6;i++){
  14. boolean hasRepeated = false;
  15. int n;
  16. do{
  17. hasRepeated = false;
  18. n=rand.nextInt(49);
  19. n++;
  20. for(int j=0;j<6;j++){
  21. if(nums[j]==n){
  22. hasRepeated = true;
  23. }
  24. }
  25. } while(hasRepeated);
  26. nums[i]=n;
  27. }
  28.  
  29. int[] choices = {0,0,0,0,0,0};
  30.  
  31. for(int i=0;i<6;i++){
  32. int n;
  33. boolean hasRepeated=false;
  34. do{
  35. System.out.print("Vuvedete unikalno chislo nomer "+(i+1)+" (ot 1 do 49): ");
  36. n= sc.nextInt();
  37. hasRepeated = false;
  38. for(int j=0;j<6;j++){
  39. if(choices[j]==n){
  40. hasRepeated=true;
  41. }
  42. }
  43. } while(n<1 || n>49 || hasRepeated);
  44. choices[i] = n;
  45. }
  46.  
  47. int matches = 0;
  48. for(int i=0;i<6;i++){
  49. for(int j=0;j<6;j++){
  50. if(nums[i]==choices[j]){
  51. matches++;
  52. continue;
  53. }
  54. }
  55. }
  56.  
  57. System.out.println();
  58.  
  59. if(matches>2){
  60. System.out.println("Pozdravleniq! Imate "+matches+" ucepeni chisla!");
  61. } else {
  62. System.out.println("Za sujalenie ne pechelite nishto");
  63. }
  64.  
  65. }
  66. }
Add Comment
Please, Sign In to add comment