Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Laba6And7 {
- public static void main(String[] args) {
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- System.out.println(Math.log(Math.abs(i*j)));
- }
- }
- }
- }
- class Laba7A {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double q;
- double E;
- double d;
- double A = 0;
- for (int i = 0; i < 3; i++) {
- System.out.println("Введите величину" + (i + 1) + "заряда (q)");
- q = scanner.nextDouble();
- System.out.println("Введите напряженность" + (i + 1) + "заряда (E)");
- E = scanner.nextDouble();
- System.out.println("Ведите расстояние" + (i + 1) + "заряда (d)");
- d = scanner.nextDouble();
- A += getA(q, E, d);
- }
- System.out.println("Средняя работа составляет: " + A/3);
- }
- private static double getA(double q, double E, double d) {
- return q * E * d;
- }
- }
- class Laba7B {
- static double[] x = new double[16];
- static double[] y = new double[20];
- static double[] z = new double[25];
- public static void main(String[] args) {
- int amountX = getAmount(x, "X");
- int amountY = getAmount(y, "Y");
- int amountZ = getAmount(z, "Z");
- System.out.println("Количество положительных до первого отрицательного в массиве X: " + amountX);
- System.out.println("Количество положительных до первого отрицательного в массиве Y: " + amountY);
- System.out.println("Количество положительных до первого отрицательного в массиве Z: " + amountZ);
- }
- public static int getAmount(double[] array, String arrayName) {
- Scanner scanner = new Scanner(System.in);
- int amount = 0;
- boolean flag = true;
- for (int i = 0; i < array.length; i++) {
- System.out.println("Введите " + (i + 1 ) + " элемент массива " + arrayName);
- array[i] = scanner.nextDouble();
- if (array[i] > 0 && flag) {
- amount++;
- } else if (array[i] < 0) {
- flag = false;
- }
- }
- return amount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement