Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.27 KB | None | 0 0
  1.  
  2. package com.metanit;
  3.  
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.util.Scanner;
  9. import javax.swing.table.DefaultTableModel;
  10. import java.io.*;
  11. import java.util.Scanner;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14.  
  15. public class Main {
  16.     private static int currentIndex = -1;
  17.  
  18.  
  19.     /*  private static Integer next(String numbers[]) {
  20.           ++currentIndex;
  21.           while (currentIndex < numbers.length && numbers[currentIndex].equals("")) {
  22.               ++currentIndex;
  23.           }
  24.           return currentIndex < numbers.length ? Integer.parseInt(numbers[currentIndex]) : null;
  25.       }*/
  26.     public static char GetUserChoice() {
  27.         System.out.println("Do you want to read from file?[Y].If you want to enter with yourself,then enter any other character");
  28.         Scanner sc = new Scanner(System.in);
  29.         char Choice = sc.next().charAt(0);
  30.         return Choice;
  31.     }
  32.  
  33.     public static void InputMatrix(int[][] Matrix) {
  34.         Scanner in = new Scanner(System.in);
  35.         for (int i = 0; i < Matrix.length; i++) {
  36.             for (int j = 0; j < Matrix[i].length; j++) {
  37.                 System.out.print("Введите элемент arr[" + i + "][" + j + "]:");
  38.                 Matrix[i][j] = in.nextInt();
  39.             }
  40.         }
  41.     }
  42.  
  43.     public static void OutputInConsole(int arr[][]) {
  44.         for (int i = 0; i < arr.length; i++) {
  45.             for (int j = 0; j < arr[i].length; j++) {
  46.                 System.out.print(arr[i][j] + "\t");
  47.             }
  48.             System.out.println();
  49.         }
  50.     }
  51.  
  52.     public static void Nol(int[][] Matrix) {
  53.         int counter = 0;
  54.         for (int i = 0; i < Matrix.length; i++) {
  55.             for (int j = 0; j < Matrix[i].length; j++) {
  56.                 if (Matrix[i][j] == 0) {
  57.                     counter++;
  58.                 }
  59.             }
  60.             if (counter > 0) {
  61.                 System.out.println(i + 1);
  62.                 counter = 0;
  63.             }
  64.         }
  65.     }
  66.  
  67.     public static void main(String[] args) throws IOException {
  68.         final int M = 5;
  69.         final int N = 3;
  70.         char Answer;
  71.         Answer = GetUserChoice();
  72.         int[][] Matrix = new int[M][N];
  73.         if (Answer == 'Y') {
  74.             InputMatrix(Matrix);
  75.             System.out.println("Your array:");
  76.             OutputInConsole(Matrix);
  77.             System.out.println("Rows in which there is zero:");
  78.         } else {
  79.             Scanner in = new Scanner(System.in);
  80.             String fileName;
  81.             System.out.println("Введите имя файла из которого хотите считатинформацию: ");
  82.             fileName = in.nextLine();
  83.             fileName = fileName + ".txt";
  84.             FileInputStream inFile = new FileInputStream(fileName);
  85.             byte[] str = new byte[inFile.available()];
  86.             inFile.read(str);
  87.             String text = new String(str);
  88.             int i, j;
  89.             for (i = 0; i < M; ++i) {
  90.                 for (j = 0; j < N; ++j) {
  91.                     // matrix[i][j] = next(numbers);
  92.                     System.out.println(Matrix[i][j]);
  93.                 }
  94.             }
  95.         }
  96.         Nol(Matrix);
  97.  
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement