Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import java.util.Collections;
  4. public class zadanie1_a {
  5.  
  6.  
  7.  
  8. public static void main(String args[])
  9. {
  10.  
  11.  
  12. {
  13. ArrayList<Double> dane = new ArrayList<Double>();
  14. ArrayList<Double> dane2 = new ArrayList<Double>();
  15. double srednia1=0.0;
  16. double srednia2=0.0;
  17. Scanner s = new Scanner(System.in);
  18. while (true)
  19. {
  20. System.out.print("Podaj liczbe, '0' konczy dzialanie programu: ");
  21. double input = s.nextDouble();
  22.  
  23. if (input == 0)
  24. {
  25. System.out.println("Zakonczenie wczytywania");
  26. break;
  27. }
  28. else if (input==2)
  29. {
  30. System.out.print("Podana liczba jest pierwsza!\n");
  31. }
  32.  
  33. else if (input%2==0)
  34. {
  35. dane.add(input);
  36. }
  37.  
  38.  
  39. else if (input%2 != 0)
  40. {
  41. dane2.add(input);
  42. if (input==3)
  43. {
  44. System.out.print("Podana liczba jest pierwsza!\n");
  45. } else if (input!=3)
  46. {
  47. for(int i=2;i*i<=input;i++)
  48. {
  49. if(input%i!=0)
  50. {
  51. System.out.print("Podana liczba jest pierwsza!\n");
  52. }
  53. }
  54. }
  55. }
  56. }
  57.  
  58. System.out.print("Wczytano liczby parzyste:\n");
  59. for (Double i : dane)
  60. {
  61. srednia1 += i;
  62.  
  63.  
  64. System.out.println(i + " ");
  65.  
  66. }
  67. System.out.print("Wczytano liczby nieparzyste:\n");
  68. for (Double j : dane2) {
  69. srednia2 += j;
  70.  
  71. System.out.println(j + " ");
  72. }
  73.  
  74. System.out.println("Srednia liczb parzystych: " + srednia1/dane.size());
  75. System.out.println("Srednia liczb nieparzystych: " +srednia2/dane2.size());
  76. System.out.println("Stosunek srednich: " +srednia1/srednia2 );
  77. // System.out.println("Liczby pierwsze: " +srednia/dane.size());
  78.  
  79. }
  80. }
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement