Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Kacper
- {
- public void Kacperr(int n)
- {
- Random rand = new Random();
- int[] tab=new int[n];
- int i, liczba=0;
- System.out.println("Zadanie 2");
- for(i=1 ; i<=n; i++)
- {
- tab[liczba] = rand.nextInt(2222 + 1 + 2222) - 2222;
- liczba++;
- }
- int j = 0;
- int min= tab[0];
- liczba = 0;
- while(j < n)
- {
- if(tab[liczba] < min)
- {
- min = tab[liczba];
- }
- j++;
- liczba++;
- }
- j = 0;
- liczba = 0;
- int ile = 0;
- while(j<n)
- {
- if(tab[liczba] == min)
- {
- ile++;
- }
- j++;
- liczba++;
- }
- System.out.println("Elementy tablicy:");
- for (int x: tab )
- {
- System.out.print(x + " ");
- }
- System.out.println("Najmniejsza wygenerowany element: " + min);
- System.out.println("ile razy wystepuje: " + ile);
- }
- }
- public class Kacper2
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- Kacper kac = new Kacper();
- int n;
- System.out.println("Wprowadz ilosc liczb");
- n = scan.nextInt();
- while(true)
- {
- if (n>=1 && n<=200)
- {
- kac.Kacperr(n);
- break;
- }
- else
- {
- System.out.println("Wprowadz liczbe z zakresu 1<=n<=200, od 1 do 200");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement