Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. class Kacper
  5. {
  6. public void Kacperr(int n)
  7. {
  8. Random rand = new Random();
  9. int[] tab=new int[n];
  10. int i, liczba=0;
  11.  
  12. System.out.println("Zadanie 2");
  13.  
  14. for(i=1 ; i<=n; i++)
  15. {
  16. tab[liczba] = rand.nextInt(2222 + 1 + 2222) - 2222;
  17. liczba++;
  18.  
  19. }
  20.  
  21. int j = 0;
  22. int min= tab[0];
  23. liczba = 0;
  24. while(j < n)
  25. {
  26. if(tab[liczba] < min)
  27. {
  28. min = tab[liczba];
  29. }
  30. j++;
  31. liczba++;
  32.  
  33.  
  34. }
  35.  
  36. j = 0;
  37. liczba = 0;
  38. int ile = 0;
  39. while(j<n)
  40. {
  41. if(tab[liczba] == min)
  42. {
  43. ile++;
  44. }
  45. j++;
  46. liczba++;
  47.  
  48. }
  49.  
  50.  
  51. System.out.println("Elementy tablicy:");
  52.  
  53. for (int x: tab )
  54. {
  55. System.out.print(x + " ");
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62. System.out.println("Najmniejsza wygenerowany element: " + min);
  63. System.out.println("ile razy wystepuje: " + ile);
  64.  
  65.  
  66.  
  67. }
  68. }
  69.  
  70.  
  71.  
  72.  
  73. public class Kacper2
  74. {
  75. public static void main(String[] args)
  76. {
  77.  
  78. Scanner scan = new Scanner(System.in);
  79. Kacper kac = new Kacper();
  80.  
  81. int n;
  82.  
  83.  
  84. System.out.println("Wprowadz ilosc liczb");
  85. n = scan.nextInt();
  86.  
  87. while(true)
  88. {
  89.  
  90.  
  91. if (n>=1 && n<=200)
  92. {
  93. kac.Kacperr(n);
  94. break;
  95. }
  96.  
  97. else
  98. {
  99. System.out.println("Wprowadz liczbe z zakresu 1<=n<=200, od 1 do 200");
  100. }
  101. }
  102.  
  103.  
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement