Advertisement
RenSafaray

Untitled

May 2nd, 2024
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.example;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ArrayProcessor {
  6.     private double[] a;
  7.     private double[] b;
  8.  
  9.     public ArrayProcessor(int n) {
  10.         a = new double[n];
  11.         b = new double[n];
  12.     }
  13.  
  14.     public void inputArray() {
  15.         Scanner scanner = new Scanner(System.in);
  16.         for (int i = 0; i < a.length; i++) {
  17.             System.out.print("Введите элемент a[" + i + "]: ");
  18.             a[i] = scanner.nextDouble();
  19.         }
  20.     }
  21.  
  22.     public void calculateArray() {
  23.         for (int i = 0; i < a.length; i++) {
  24.             if (a[i] % 2 == 0 && a[i] % 5 == 0) {
  25.                 b[i] = a[i];
  26.             } else if (a[i] % 2 == 0) {
  27.                 b[i] = Math.pow(a[i], 2);
  28.             } else if (a[i] % 5 == 0) {
  29.                 b[i] = Math.pow(a[i], 3);
  30.             } else {
  31.                 b[i] = 1 / a[i];
  32.             }
  33.         }
  34.     }
  35.  
  36.     public void printArray() {
  37.         System.out.println("Массив b:");
  38.         for (int i = 0; i < b.length; i++) {
  39.             System.out.println("b[" + i + "] = " + b[i]);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement