Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KB
- import java.util.Scanner;
- public class IntroductionJava9_9 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Choose 1 for reversed, 2 for average and 3 for equation:");
- int choice = Integer.parseInt(sc.nextLine());
- if (choice == 1) {
- System.out.println("Type your number:");
- int number = Integer.parseInt(sc.nextLine());
- System.out.println(reversed(number));
- } else if (choice == 2) {
- System.out.println("Type length of array:");
- int lengthArr = Integer.parseInt(sc.nextLine());
- int[] arr = new int[lengthArr];
- if (lengthArr == 0) {
- System.out.println("NO ELEMENTS IN ARRAY!");
- } else {
- System.out.println("Type elements of array:");
- for (int i = 0; i < arr.length; i++) {
- arr[i] = Integer.parseInt(sc.nextLine());
- }
- System.out.println(average(arr));
- }
- } else if (choice == 3) {
- System.out.println("Type 'a' and 'b':");
- int a = Integer.parseInt(sc.nextLine());
- if (a == 0) {
- System.out.println("'A' CAN'T BE 0");
- }
- int b = Integer.parseInt(sc.nextLine());
- System.out.println(equation(a, b));
- } else {
- System.out.println("1, 2 OR 3 NOT DETECTED");
- }
- }
- public static int reversed(int a) {
- int reversed = 0;
- while (a != 0) {
- int digit = a % 10;
- reversed = reversed * 10 + digit;
- a /= 10;
- }
- return reversed;
- }
- public static float average(int[] array) {
- float sum = 0;
- float average = 0;
- for (int i = 0; i < array.length; i++) {
- sum = sum + array[i];
- average = sum / array.length;
- ;
- }
- return average;
- }
- public static float equation(float a, float b) {
- return -b / a;
- }
- }
- RAW Paste Data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement