Advertisement
Talar97

Kolokwium Z1 (0,8/1pkt)

Dec 11th, 2017
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.Talar;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Random rand = new Random();
  9.         int max = Integer.MIN_VALUE;
  10.         int min = Integer.MAX_VALUE;
  11.         int r1 = 0; int r2 = 0;
  12.         int ilosc = 0;
  13.         long iloczyn = 1;
  14.         int suma = 0;
  15.  
  16.         do{
  17.             r1 = rand.nextInt(150)-50;
  18.             ilosc++;
  19.             if(max<r1) { max = r1; }
  20.             else if(min>r1) { min = r1; }
  21.  
  22.             if(r1>0 && r1%2==0){
  23.                 iloczyn *= r1;
  24.             }
  25.  
  26.             //System.out.println(r1);
  27.         }
  28.         while(r1!=0);
  29.  
  30.         System.out.print("max: " +max + ", min:" + min + "\nIloczyn liczb parzystych dodatnich: " + iloczyn + "\n");
  31.  
  32.         for(int i = 0; i<ilosc; i++){
  33.             r2 = rand.nextInt(25)-25;
  34.             if(r2!=0){
  35.                 if(i%2==0){
  36.                     suma += r2;
  37.                 }
  38.             }
  39.  
  40.             //System.out.println(r2);
  41.         }
  42.  
  43.         System.out.println("Suma: " + suma);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement