Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. 1.1
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Area {
  6. public static void main(String[] args) {
  7. Scanner input = new Scanner(System.in);
  8. System.out.println("Podaj promień koła: ");
  9. int r = input.nextInt();
  10. double result = r*r*3.14;
  11. System.out.println("Pole koła o promieniu " +r+ " to: " +result);
  12.  
  13. }
  14. }
  15.  
  16. 1.2
  17.  
  18. import java.util.Scanner;
  19.  
  20. public class Division {
  21. public static void main(String[] args) {
  22. Scanner input = new Scanner(System.in);
  23. System.out.println("Podaj pierwszą liczbę: ");
  24. double first = input.nextDouble();
  25. System.out.println("Podaj drugą liczbę: ");
  26. double second = input.nextDouble();
  27. double result = (first/second);
  28. System.out.println("Wynik dzielenia pierwszej liczby przez drugą to: " +result);
  29.  
  30. }
  31. }
  32.  
  33. 1.3
  34.  
  35. import java.util.Scanner;
  36.  
  37. public class Age {
  38. public static void main(String[] args) {
  39. Scanner input = new Scanner(System.in);
  40. System.out.println("Podaj, ile masz lat: ");
  41. int age = input.nextInt();
  42. if (age < 18) {
  43. System.out.println("Nie możesz głosować");
  44. } else {
  45. if (age >= 18) {
  46. if (age < 35) {
  47. System.out.println("Możesz głosować, ale nie możesz zostać wybranym na prezydenta");
  48. } else
  49. System.out.println("Możesz kandydować na prezydenta państwa");
  50. }
  51. }
  52. }
  53. }
  54.  
  55. 1.4
  56.  
  57. import java.util.Scanner;
  58.  
  59. public class Sort {
  60. public static void main(String[] args) {
  61. Scanner input = new Scanner(System.in);
  62.  
  63. System.out.println("Podaj pierwszą liczbę: ");
  64. int a = input.nextInt();
  65. System.out.println("Podaj drugą liczbę: ");
  66. int b = input.nextInt();
  67. System.out.println("Podaj trzecią liczbę: ");
  68. int c = input.nextInt();
  69.  
  70. if (a < b) {
  71. if (b > c) {
  72. if (a < c) System.out.println("Liczby posortowane od najmniejszej: " + a + "," + c + "," + b);
  73. else System.out.println("Liczby posortowane od najmniejszej: " + c + "," + a + "," + b);
  74. } else System.out.println("Liczby posortowane od najmniejszej: " + a + "," + b + "," + c);
  75. } else {
  76. if (a > c) {
  77. if (b < c) System.out.println("Liczby posortowane od najmniejszej: " + b + "," + c + "," + a);
  78. else System.out.println("Liczby posortowane od najmniejszej: " + c + "," + b + "," + a);
  79. } else System.out.println("Liczby posortowane od najmniejszej: " + b +"," + a + "," + c);
  80. }
  81. }
  82. }
  83.  
  84. 2.1
  85.  
  86. public class For {
  87. public static void main(String[] args) {
  88. for (int i=1; i<=10;i++)
  89. System.out.println(i);
  90. }
  91. }
  92.  
  93. 2.2
  94.  
  95. public class For {
  96. public static void main(String[] args) {
  97. for (int i=5; i<=10;i++)
  98. System.out.println(i);
  99. }
  100. }
  101.  
  102. 2.3
  103.  
  104. public class For {
  105. public static void main(String[] args) {
  106. for (int i=10; i >=1; i--)
  107. System.out.println(i);
  108. }
  109. }
  110.  
  111. 2.4 a)
  112.  
  113. public class For {
  114. public static void main(String[] args) {
  115. for (int i=1; i <=100; i++)
  116. if (i % 3 == 0) System.out.println(i);
  117. }
  118. }
  119.  
  120. 2.4 b)
  121.  
  122. public class For {
  123. public static void main(String[] args) {
  124. for (int i=1; i <=100; i++)
  125. if (i % 5 == 0) System.out.println(i);
  126. }
  127. }
  128.  
  129. 2.4 c)
  130.  
  131. public class For {
  132. public static void main(String[] args) {
  133. for (int i=1; i <=100; i++)
  134. if (i % 3 == 0 && i % 5 == 0) System.out.println(i);
  135. }
  136. }
  137.  
  138. 2.4 d)
  139.  
  140. public class For {
  141. public static void main(String[] args) {
  142. for (int i=1; i <=100; i++)
  143. if (i % 3 == 0 || i % 5 == 0) System.out.println(i);
  144. }
  145. }
  146.  
  147.  
  148. 2.5
  149.  
  150. import java.util.Scanner;
  151.  
  152. public class For {
  153. public static void main(String[] args) {
  154. Scanner input = new Scanner(System.in);
  155.  
  156. System.out.println("Podaj pierwszą liczbę: ");
  157. int first = input.nextInt();
  158. System.out.println("Podaj drugą liczbę: ");
  159. int second = input.nextInt();
  160.  
  161. if (first < second) {
  162. for (int i = first; i <= second; i++)
  163. System.out.println(i);
  164. } else {
  165. for (int i = second; i <= first; i++)
  166. System.out.println(i);
  167. }
  168. }
  169. }
  170.  
  171. 2.6
  172.  
  173. public class Multiplication {
  174. public static void main(String[] args) {
  175. for (int i = 1; i <= 10; i++) {
  176. for (int j = 1; j <= 10; j++) {
  177. System.out.printf("%5d",i*j);
  178. }
  179. System.out.println();
  180. }
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement