Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class Main
- {
- public static double[][] InputArray()
- {
- Scanner in = new Scanner (System.in); //класс для ввода с клавиатуры
- System.out.print("Введите число строк: ");
- int n = in.nextInt(); // число строк
- System.out.print("Введите число столбцов: ");
- int m = in.nextInt(); // число столбцов
- double array[][] = new double[n][m];
- return array;
- }
- public static void FillArray(double[][] array)
- {
- Random rnd = new Random();
- for(int i=0;i<array.length;i++)
- {
- for(int j=0;j<array[i].length;j++)
- array[i][j] = rnd.nextInt(100);// Генерация чисел от 0 до 100
- }
- }
- public static void OutputArray(double[][] array)
- {
- for(int i=0;i<array.length;i++)
- {
- for(int j=0;j<array[i].length;j++)
- System.out.print(array[i][j] + " ");
- System.out.println();
- }
- }
- public static void ReduceLastColumnItems(double[][] array)
- {
- for(int i=0;i<array.length;i++)
- {
- for(int j=0;j<array[i].length;j++)
- if(j == array[i].length - 1) // если это последний столбец
- array[i][j] *= 0.95;
- }
- }
- public static void main(String[] args)
- {
- double[][] array = InputArray(); // создаем массив
- FillArray(array); // заполняем случайными числами
- System.out.println("Исходный массив: ");
- OutputArray(array); // выводим массив
- ReduceLastColumnItems(array);
- System.out.println("Итоговый массив: ");
- OutputArray(array); // выводим массив
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement