Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. 2ra . package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int number = Integer.parseInt(scanner.nextLine());
  10. if (number % 10 == 0) {
  11. System.out.println("The number is divisible by 10");
  12. } else if (number % 7 == 0) {
  13. System.out.println("The number is divisible by 7");
  14. } else if (number % 6 == 0) {
  15. System.out.println("The number is divisible by 6");
  16. } else if (number % 3 == 0) {
  17. System.out.println("The number is divisible by 3");
  18.  
  19. } else if (number % 2 == 0) {
  20. System.out.println("The number is divisible by 2");
  21.  
  22. }
  23. else{
  24. System.out.println("Not divisible");
  25. }
  26. }
  27. }
  28.  
  29. 3.ta import java.util.Scanner;
  30.  
  31. public class JF_3_Vacation {
  32. public static void main(String[] args) {
  33. Scanner scanner = new Scanner(System.in);
  34.  
  35. int peopleNum = Integer.parseInt(scanner.nextLine());
  36. String typePeople = scanner.nextLine();
  37. String day = scanner.nextLine();
  38.  
  39. double price = 0;
  40.  
  41. switch (typePeople) {
  42. case "Students":
  43. if ("Friday".equals(day)) {
  44. price = 8.45;
  45. } else if ("Saturday".equals(day)) {
  46. price = 9.80;
  47. } else if ("Sunday".equals(day)) {
  48. price = 10.46;
  49. }
  50. break;
  51. case "Business":
  52. if ("Friday".equals(day)) {
  53. price = 10.90;
  54. } else if ("Saturday".equals(day)) {
  55. price = 15.60;
  56. } else if ("Sunday".equals(day)) {
  57. price = 16;
  58. }
  59. break;
  60. case "Regular":
  61. if ("Friday".equals(day)) {
  62. price = 15;
  63. } else if ("Saturday".equals(day)) {
  64. price = 20.00;
  65. } else if ("Sunday".equals(day)) {
  66. price = 22.50;
  67. }
  68. break;
  69. }
  70. double subTotal = peopleNum * price;
  71. if ("Students".equals(typePeople) && peopleNum >= 30) {
  72. subTotal *= 0.85;
  73. }
  74. else if ("Business".equals(typePeople) && peopleNum >= 100) {
  75. subTotal = (peopleNum - 10) * price; }
  76. else if ("Regular".equals(typePeople) && peopleNum >= 10 && peopleNum <= 20) {
  77. subTotal *= 0.95;
  78. }
  79. System.out.printf("Total price: %.2f", subTotal);
  80.  
  81. }
  82. }
  83.  
  84. 4ta . package com.company;
  85.  
  86. import java.util.Scanner;
  87.  
  88. public class Main {
  89.  
  90. public static void main(String[] args) {
  91. Scanner scanner = new Scanner(System.in);
  92. int startNumber = Integer.parseInt(scanner.nextLine());
  93. int endNumber = Integer.parseInt(scanner.nextLine());
  94. int sum =0;
  95. for (int i = startNumber; i <= endNumber; i++) {
  96. System.out.print(i + " ");
  97. sum +=i;
  98. }
  99. System.out.printf("%nSum: %d",sum);
  100.  
  101. }
  102. }
  103. 5ta import java.util.Scanner;
  104.  
  105. public class Login {
  106. public static void main(String[] args) {
  107. Scanner scanner = new Scanner(System.in);
  108.  
  109. String username = scanner.nextLine();
  110. String password = "";
  111. int count = 0;
  112.  
  113.  
  114. for (int i = username.length() - 1; i >= 0; i--) {
  115. password += username.charAt(i);
  116. }
  117. String input = scanner.nextLine();
  118. while (!input.equals(password)) {
  119. count++;
  120. if (count == 4) {
  121. System.out.printf("User %s blocked!", username);
  122. return;
  123. }
  124. System.out.println("Incorrect password. Try again.");
  125.  
  126. input = scanner.nextLine();
  127. }
  128. System.out.printf("User %s logged in.", username);
  129. }
  130. }
  131. 6ta package com.company;
  132.  
  133. import java.util.Scanner;
  134.  
  135. public class Main {
  136.  
  137. public static void main(String[] args) {
  138. Scanner scanner = new Scanner(System.in);
  139. String input = scanner.nextLine();
  140. int totalSum = 0;
  141.  
  142. for (int i = 0; i < input.length(); i++) {
  143. int digit = Integer.parseInt("" +input.charAt(i));
  144. int currentSum = 1;
  145. for (int j = digit; j>=1 ; j--) {
  146. currentSum *= j;
  147. }
  148. totalSum+=currentSum;
  149. }
  150. int number = Integer.parseInt(input);
  151. if(number == totalSum){
  152. System.out.println("yes");
  153. }else{
  154. System.out.println("no");
  155. }
  156.  
  157.  
  158. }
  159. }
  160. 7ma import java.util.Scanner;
  161.  
  162. public class VendingMachine {
  163. public static void main(String[] args) {
  164.  
  165. Scanner scanner = new Scanner(System.in);
  166. double sum = 0;
  167. int total = 0;
  168.  
  169. String textInput = "";
  170. while (true) {
  171. textInput = scanner.nextLine();
  172. if (textInput.equals("Start")) {
  173. break;
  174. }
  175. double coin = Double.parseDouble(textInput);
  176. if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2) {
  177. sum += coin;
  178. } else {
  179. System.out.println("Cannot accept " + coin);
  180. }
  181. }
  182.  
  183.  
  184. double price = 0;
  185. String input ;
  186. boolean flag = false;
  187. while (true) {
  188. input = scanner.nextLine();
  189. switch (input.toLowerCase()) {
  190. case "nuts":
  191. price = 2;
  192. flag = true;
  193. break;
  194. case "water":
  195. price = 0.7;
  196. flag = true;
  197. break;
  198. case "crisps":
  199. price = 1.5;
  200. flag = true;
  201. break;
  202. case "soda":
  203. price = 0.8;
  204. flag = true;
  205. break;
  206. case "coke":
  207. price = 1;
  208. flag = true;
  209. break;
  210. }
  211. if (input.equals("End")) {
  212. break;
  213. }
  214. if (sum < price) {
  215. System.out.println("Sorry, not enough money");
  216. } else if (flag) {
  217. System.out.println("Purchased " + input);
  218. sum -= price;
  219. } else {
  220. System.out.println("Invalid product");
  221. }
  222.  
  223. }
  224. System.out.printf("Change: %.2f", sum);
  225.  
  226.  
  227. }
  228. }
  229.  
  230. 8ma package com.company;
  231.  
  232. import java.util.Scanner;
  233.  
  234. public class Main {
  235.  
  236. public static void main(String[] args) {
  237. Scanner scanner = new Scanner(System.in);
  238. int n = Integer.parseInt(scanner.nextLine());
  239.  
  240. for (int i = 1; i <=n ; i++) {
  241. for (int j = 0; j < i; j++) {
  242. System.out.print(i + " ");
  243.  
  244. }
  245. System.out.println();
  246. }
  247.  
  248. }
  249.  
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement