Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Laba6And7 {
  4. public static void main(String[] args) {
  5. for (int i = 0; i < 10; i++) {
  6. for (int j = 0; j < 10; j++) {
  7. System.out.println(Math.log(Math.abs(i*j)));
  8. }
  9. }
  10. }
  11. }
  12.  
  13. class Laba7A {
  14. public static void main(String[] args) {
  15. Scanner scanner = new Scanner(System.in);
  16.  
  17. double q;
  18. double E;
  19. double d;
  20.  
  21. double A = 0;
  22.  
  23. for (int i = 0; i < 3; i++) {
  24. System.out.println("Введите величину" + (i + 1) + "заряда (q)");
  25. q = scanner.nextDouble();
  26.  
  27. System.out.println("Введите напряженность" + (i + 1) + "заряда (E)");
  28. E = scanner.nextDouble();
  29.  
  30. System.out.println("Ведите расстояние" + (i + 1) + "заряда (d)");
  31. d = scanner.nextDouble();
  32.  
  33. A += getA(q, E, d);
  34. }
  35.  
  36. System.out.println("Средняя работа составляет: " + A/3);
  37. }
  38.  
  39. private static double getA(double q, double E, double d) {
  40. return q * E * d;
  41. }
  42. }
  43.  
  44. class Laba7B {
  45. static double[] x = new double[16];
  46. static double[] y = new double[20];
  47. static double[] z = new double[25];
  48.  
  49. public static void main(String[] args) {
  50. int amountX = getAmount(x, "X");
  51. int amountY = getAmount(y, "Y");
  52. int amountZ = getAmount(z, "Z");
  53.  
  54. System.out.println("Количество положительных до первого отрицательного в массиве X: " + amountX);
  55. System.out.println("Количество положительных до первого отрицательного в массиве Y: " + amountY);
  56. System.out.println("Количество положительных до первого отрицательного в массиве Z: " + amountZ);
  57. }
  58.  
  59. public static int getAmount(double[] array, String arrayName) {
  60. Scanner scanner = new Scanner(System.in);
  61.  
  62. int amount = 0;
  63. boolean flag = true;
  64.  
  65. for (int i = 0; i < array.length; i++) {
  66. System.out.println("Введите " + (i + 1 ) + " элемент массива " + arrayName);
  67.  
  68. array[i] = scanner.nextDouble();
  69.  
  70. if (array[i] > 0 && flag) {
  71. amount++;
  72. } else if (array[i] < 0) {
  73. flag = false;
  74. }
  75. }
  76.  
  77. return amount;
  78. }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement