Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. /*
  2. import java.util.Random;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. double x,y,xtemp,ytemp,granica,wynik;
  7. double dobre=0;
  8. double zle=0;
  9. int p=200;
  10. Random losuj = new Random();
  11. for(int i=0;i<p;i++){
  12. xtemp=losuj.nextInt(1000);
  13. ytemp=losuj.nextInt(1000);
  14. x=xtemp/1000;
  15. y=ytemp/1000;
  16. granica=Math.sqrt(x);
  17.  
  18. if(y<=granica){
  19. dobre++;
  20. }
  21. else{
  22. zle++;
  23. }
  24. }
  25. System.out.println("Ilosc danych zawierajacych sie "+dobre);
  26. System.out.println("Ilosc danych niezawierajacych sie "+zle);
  27. wynik=dobre/p;
  28. System.out.println("Pole wynosi "+wynik);
  29. }
  30. }*/
  31. /*
  32. import java.util.Scanner;
  33. class Main{
  34. public static void main(String[] args){
  35. Scanner scanner= new Scanner(System.in);
  36. System.out.print("Podaj ktory wyraz ciagu obliczasz ");
  37. int k=scanner.nextInt();
  38. System.out.println(k+" -ty wyraz ciagu to " + ciag(k));
  39. }
  40. static int ciag(int n){
  41. if(n==1){
  42. return 1;
  43. }
  44. if(n==2){
  45. return 3;
  46. }
  47. else{
  48. return ciag(n-1) + ciag(n-2);
  49. }
  50. }
  51. }
  52. */
  53. /*
  54. import java.util.Scanner;
  55. class Main{
  56. public static void main(String[] args){
  57. Scanner scanner = new Scanner(System.in);
  58. System.out.print("Podaj wyraz ciągu do obliczenia: ");
  59. int r=scanner.nextInt();
  60. int tab[] = new int[r+1];
  61. for(int i=1;i<=r;i++){
  62. if(i==1 || i==2){
  63. tab[i]=1;
  64. }
  65. else{
  66. if(i%3==0){
  67. tab[i]=2*tab[i-1];
  68. }
  69.  
  70. if(i%3==1){
  71. tab[i]=(int) Math.pow(tab[i-2],2);
  72. }
  73. if(i%3==2){
  74. tab[i]=(int) Math.pow(2,tab[i-3]);
  75. }
  76. }
  77. }
  78. System.out.println(r+" -ty wyraz ciagu to "+tab[r]);
  79. }
  80. }
  81. */
  82. import java.util.Scanner;
  83. class Main{
  84. public static void main(String[] args){
  85. int[] wartosci = {500,200,100,50,20,10,5,2,1};
  86. int[] ilosci = {7,0,1,1,4,1,4,7,30};
  87. Scanner scanner = new Scanner(System.in);
  88. int zl;
  89. int gr;
  90. int o = 0;
  91. System.out.print("Podaj liczbe zl: ");
  92. zl=scanner.nextInt();
  93. System.out.print("Podaj liczbe gr: ");
  94. gr=scanner.nextInt();
  95. int reszta = (zl*100)+gr;
  96. int n = ilosci.length;
  97. while(reszta>0){
  98. if(reszta-wartosci[o]>=0){
  99. if(ilosci[o]>0){
  100. reszta=reszta-wartosci[o];
  101. if(wartosci[o]>=100){
  102. System.out.println("Wydano monete o wartosci: "+wartosci[o]/100+"zł");}
  103. else{
  104. System.out.println("Wydano monete o wartosci: "+wartosci[o]+"gr");
  105. }
  106. ilosci[o]=ilosci[o]-1;
  107. }
  108. else{
  109. o++;
  110. if(o>=n){
  111. System.out.println("Nie da sie wydac wiecej reszty."); break;
  112. }
  113. }
  114. }
  115. else{
  116. o++;
  117. if(o>=n){
  118. System.out.println("Nie da się wydać więcej reszty."); break;
  119. }
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement