Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.metanit;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- import javax.swing.table.DefaultTableModel;
- import java.io.*;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Main {
- private static int currentIndex = -1;
- /* private static Integer next(String numbers[]) {
- ++currentIndex;
- while (currentIndex < numbers.length && numbers[currentIndex].equals("")) {
- ++currentIndex;
- }
- return currentIndex < numbers.length ? Integer.parseInt(numbers[currentIndex]) : null;
- }*/
- public static char GetUserChoice() {
- System.out.println("Do you want to read from file?[Y].If you want to enter with yourself,then enter any other character");
- Scanner sc = new Scanner(System.in);
- char Choice = sc.next().charAt(0);
- return Choice;
- }
- public static void InputMatrix(int[][] Matrix) {
- Scanner in = new Scanner(System.in);
- for (int i = 0; i < Matrix.length; i++) {
- for (int j = 0; j < Matrix[i].length; j++) {
- System.out.print("Введите элемент arr[" + i + "][" + j + "]:");
- Matrix[i][j] = in.nextInt();
- }
- }
- }
- public static void OutputInConsole(int arr[][]) {
- for (int i = 0; i < arr.length; i++) {
- for (int j = 0; j < arr[i].length; j++) {
- System.out.print(arr[i][j] + "\t");
- }
- System.out.println();
- }
- }
- public static void Nol(int[][] Matrix) {
- int counter = 0;
- for (int i = 0; i < Matrix.length; i++) {
- for (int j = 0; j < Matrix[i].length; j++) {
- if (Matrix[i][j] == 0) {
- counter++;
- }
- }
- if (counter > 0) {
- System.out.println(i + 1);
- counter = 0;
- }
- }
- }
- public static void main(String[] args) throws IOException {
- final int M = 5;
- final int N = 3;
- char Answer;
- Answer = GetUserChoice();
- int[][] Matrix = new int[M][N];
- if (Answer == 'Y') {
- InputMatrix(Matrix);
- System.out.println("Your array:");
- OutputInConsole(Matrix);
- System.out.println("Rows in which there is zero:");
- } else {
- Scanner in = new Scanner(System.in);
- String fileName;
- System.out.println("Введите имя файла из которого хотите считатинформацию: ");
- fileName = in.nextLine();
- fileName = fileName + ".txt";
- FileInputStream inFile = new FileInputStream(fileName);
- byte[] str = new byte[inFile.available()];
- inFile.read(str);
- String text = new String(str);
- int i, j;
- for (i = 0; i < M; ++i) {
- for (j = 0; j < N; ++j) {
- // matrix[i][j] = next(numbers);
- System.out.println(Matrix[i][j]);
- }
- }
- }
- Nol(Matrix);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement