Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example;
- import java.util.Scanner;
- public class ArrayProcessor {
- private double[] a;
- private double[] b;
- public ArrayProcessor(int n) {
- a = new double[n];
- b = new double[n];
- }
- public void inputArray() {
- Scanner scanner = new Scanner(System.in);
- for (int i = 0; i < a.length; i++) {
- System.out.print("Введите элемент a[" + i + "]: ");
- a[i] = scanner.nextDouble();
- }
- }
- public void calculateArray() {
- for (int i = 0; i < a.length; i++) {
- if (a[i] % 2 == 0 && a[i] % 5 == 0) {
- b[i] = a[i];
- } else if (a[i] % 2 == 0) {
- b[i] = Math.pow(a[i], 2);
- } else if (a[i] % 5 == 0) {
- b[i] = Math.pow(a[i], 3);
- } else {
- b[i] = 1 / a[i];
- }
- }
- }
- public void printArray() {
- System.out.println("Массив b:");
- for (int i = 0; i < b.length; i++) {
- System.out.println("b[" + i + "] = " + b[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement