Advertisement
Guest User

Task4

a guest
Mar 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class Main
  5. {
  6.     public static double[][] InputArray()
  7.     {
  8.         Scanner in = new Scanner (System.in); //класс для ввода с клавиатуры
  9.         System.out.print("Введите число строк: ");
  10.         int n = in.nextInt(); // число строк
  11.         System.out.print("Введите число столбцов: ");
  12.         int m = in.nextInt(); // число столбцов
  13.         double array[][] = new double[n][m];
  14.         return array;
  15.     }
  16.    
  17.     public static void FillArray(double[][] array)
  18.     {
  19.         Random rnd = new Random();
  20.         for(int i=0;i<array.length;i++)
  21.         {
  22.             for(int j=0;j<array[i].length;j++)
  23.                 array[i][j] =  rnd.nextInt(100);// Генерация чисел от 0 до 100
  24.         }
  25.     }
  26.    
  27.     public static void OutputArray(double[][] array)
  28.     {
  29.         for(int i=0;i<array.length;i++)
  30.         {
  31.             for(int j=0;j<array[i].length;j++)
  32.                 System.out.print(array[i][j] + " ");
  33.             System.out.println();
  34.         }
  35.     }
  36.    
  37.     public static void ReduceLastColumnItems(double[][] array)
  38.     {
  39.         for(int i=0;i<array.length;i++)
  40.         {
  41.             for(int j=0;j<array[i].length;j++)
  42.                 if(j == array[i].length - 1) // если это последний столбец
  43.                     array[i][j] *= 0.95;
  44.         }
  45.     }
  46.    
  47.     public static void main(String[] args)
  48.     {
  49.         double[][] array = InputArray(); // создаем массив
  50.         FillArray(array); // заполняем случайными числами
  51.         System.out.println("Исходный массив: ");
  52.         OutputArray(array); // выводим массив
  53.         ReduceLastColumnItems(array);
  54.         System.out.println("Итоговый массив: ");
  55.         OutputArray(array); // выводим массив
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement