Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Reverse {
- // :NOTE: naming -- it's better to name "matrix" not "mass", do not abbreviate words incomprehensibly
- public static int[][] addLineInMass(int[][] mass, int numStr) {
- // :NOTE: same -- naming
- if (mass.length == numStr + 1) {
- // :NOTE: mass1? -- not understandable name
- int[][] mass1 = new int[mass.length * 2][];
- for (int i = 0; i < mass.length; i++) {
- mass1[i] = new int[mass[i].length];
- System.arraycopy(mass[i], 0, mass1[i], 0, mass[i].length);
- }
- Arrays.fill(mass1, mass.length, mass.length*2, new int[1]);
- mass = mass1;
- }
- return mass;
- }
- // :NOTE: same -- naming
- public static int[] addDigitInMass(int[] mass, int numDig) {
- if (mass.length == numDig + 1) {
- // :NOTE: same -- naming
- int[] mass1 = new int[mass.length * 2];
- System.arraycopy(mass, 0, mass1, 0, mass.length);
- mass = mass1;
- }
- return mass;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- // :NOTE: same -- naming (massiv is not a word from English)
- int[][] mass = new int[1][1];
- // :NOTE: same -- naming
- int[] massSize = new int[1];
- int numStr = 0;
- int numElem = 0;
- while (in.hasNextLine()) {
- Scanner str = new Scanner(in.nextLine());
- while (str.hasNextInt()) {
- mass[numStr][numElem] = str.nextInt();
- mass[numStr] = addDigitInMass(mass[numStr], numElem);
- numElem++;
- }
- mass = addLineInMass(mass, numStr);
- massSize = addDigitInMass(massSize, numStr);
- numStr++;
- massSize[numStr - 1] = numElem;
- numElem = 0;
- }
- // :NOTE: your scanner is not used in the next "for" block of code, so you should close it here
- for (int i = numStr - 1; i > -1; i--) {
- for (int j = massSize[i] - 1; j > -1; j--) {
- System.out.print(mass[i][j] + " ");
- }
- System.out.println();
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement