Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- public class Main {
- public static void main(String [] args) {
- Random random = new Random();
- List<Integer> lista1 = new ArrayList<Integer>();
- List<Integer> lista2 = new ArrayList<Integer>();
- int liczba, licznik = 0;
- System.out.println("LISTA 1:");
- do{
- liczba = random.nextInt(150 + 1 + 150) - 150;
- if(liczba == 0)
- break;
- lista1.add(liczba);
- ++licznik;
- System.out.print(liczba + ", ");
- }while (liczba != 0);
- System.out.println("\n\nLISTA 2: ");
- for(int i = 0; i < licznik; i++){
- liczba = random.nextInt(10 + 1 + 10) - 10;
- lista2.add(liczba);
- System.out.print(liczba + ", ");
- }
- int suma = 0;
- //suma parzystych dodatnich z 1 petli
- for(int x : lista1){
- if(x > 0 && x%2 == 0)
- suma += x;
- }
- int iloczyn = 1;
- //iloczyn nieparzystych ujemnych z 2 petli
- for(int x : lista2){
- if(x < 0 && x%2 ==1)
- iloczyn *= x;
- }
- int wynik = suma / iloczyn;
- System.out.println("WYNIK = " + wynik);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement