Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.Collections;
- public class zadanie1_a {
- public static void main(String args[])
- {
- {
- ArrayList<Double> dane = new ArrayList<Double>();
- ArrayList<Double> dane2 = new ArrayList<Double>();
- double srednia1=0.0;
- double srednia2=0.0;
- Scanner s = new Scanner(System.in);
- while (true)
- {
- System.out.print("Podaj liczbe, '0' konczy dzialanie programu: ");
- double input = s.nextDouble();
- if (input == 0)
- {
- System.out.println("Zakonczenie wczytywania");
- break;
- }
- else if (input==2)
- {
- System.out.print("Podana liczba jest pierwsza!\n");
- }
- else if (input%2==0)
- {
- dane.add(input);
- }
- else if (input%2 != 0)
- {
- dane2.add(input);
- if (input==3)
- {
- System.out.print("Podana liczba jest pierwsza!\n");
- } else if (input!=3)
- {
- for(int i=2;i*i<=input;i++)
- {
- if(input%i!=0)
- {
- System.out.print("Podana liczba jest pierwsza!\n");
- }
- }
- }
- }
- }
- System.out.print("Wczytano liczby parzyste:\n");
- for (Double i : dane)
- {
- srednia1 += i;
- System.out.println(i + " ");
- }
- System.out.print("Wczytano liczby nieparzyste:\n");
- for (Double j : dane2) {
- srednia2 += j;
- System.out.println(j + " ");
- }
- System.out.println("Srednia liczb parzystych: " + srednia1/dane.size());
- System.out.println("Srednia liczb nieparzystych: " +srednia2/dane2.size());
- System.out.println("Stosunek srednich: " +srednia1/srednia2 );
- // System.out.println("Liczby pierwsze: " +srednia/dane.size());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement