Advertisement
16223

1

Oct 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. KB
  2. import java.util.Scanner;
  3.  
  4. public class IntroductionJava9_9 {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. System.out.println("Choose 1 for reversed, 2 for average and 3 for equation:");
  11. int choice = Integer.parseInt(sc.nextLine());
  12. if (choice == 1) {
  13. System.out.println("Type your number:");
  14. int number = Integer.parseInt(sc.nextLine());
  15. System.out.println(reversed(number));
  16. } else if (choice == 2) {
  17. System.out.println("Type length of array:");
  18. int lengthArr = Integer.parseInt(sc.nextLine());
  19. int[] arr = new int[lengthArr];
  20. if (lengthArr == 0) {
  21. System.out.println("NO ELEMENTS IN ARRAY!");
  22. } else {
  23. System.out.println("Type elements of array:");
  24. for (int i = 0; i < arr.length; i++) {
  25. arr[i] = Integer.parseInt(sc.nextLine());
  26. }
  27. System.out.println(average(arr));
  28. }
  29. } else if (choice == 3) {
  30. System.out.println("Type 'a' and 'b':");
  31. int a = Integer.parseInt(sc.nextLine());
  32. if (a == 0) {
  33. System.out.println("'A' CAN'T BE 0");
  34. }
  35. int b = Integer.parseInt(sc.nextLine());
  36. System.out.println(equation(a, b));
  37. } else {
  38. System.out.println("1, 2 OR 3 NOT DETECTED");
  39. }
  40. }
  41.  
  42. public static int reversed(int a) {
  43. int reversed = 0;
  44. while (a != 0) {
  45. int digit = a % 10;
  46. reversed = reversed * 10 + digit;
  47. a /= 10;
  48. }
  49. return reversed;
  50.  
  51. }
  52.  
  53. public static float average(int[] array) {
  54. float sum = 0;
  55. float average = 0;
  56. for (int i = 0; i < array.length; i++) {
  57. sum = sum + array[i];
  58. average = sum / array.length;
  59. ;
  60. }
  61. return average;
  62. }
  63.  
  64. public static float equation(float a, float b) {
  65. return -b / a;
  66. }
  67. }
  68. RAW Paste Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement