Advertisement
ultravibez

booleanRectangle Homework

Sep 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         int[][] arr = {{1, 2, 3}, {1, 2, 3, 4}, {4, 5, 6, 7}};
  7.         int[] arr2 = {1, 2, 3, 4, 5, 6, 7};
  8.         System.out.println(subArray(arr, arr2));
  9.         boolean array[][] = new boolean[5][10];
  10.         boolRectangle(array);
  11.         boolPrintArr(array);
  12.     }
  13.  
  14.     public static int subArray(int[][] arr, int[] arr2) {
  15.         int index = -1;
  16.         int counter = 0;
  17.         for (int i = 0; i < arr.length; i++) {
  18.             for (int j = 0; j < arr[i].length; j++) {
  19.                 if (arr[i][j] == arr2[counter] && counter < arr2.length - 1) {
  20.                     counter++;
  21.                     index = i;
  22.                 }
  23.             }
  24.             counter = 0;
  25.         }
  26.         return index;
  27.     }
  28.  
  29.     public static void printArr(boolean[] arr) {
  30.         for (int i = 0; i < arr.length; i++) {
  31.             if (i % 2 == 0)
  32.                 arr[i] = true;
  33.             System.out.println(arr[i]);
  34.         }
  35.     }
  36.  
  37.     public static void boolRectangle(boolean[][] arr) {
  38.         for (int col = 0; col < arr.length; col++) {
  39.             for (int row = 0; row < arr[col].length; row++) {
  40.                 if (row == 0 || col == arr.length - 1 || col == 0 || row == arr[col].length - 1)
  41.                     arr[col][row] = true;
  42.             }
  43.         }
  44.     }
  45.  
  46.     public static void boolPrintArr(boolean[][] arr) {
  47.         for (int i = 0; i < arr.length; i++) {
  48.             for (int j = 0; j < arr[i].length; j++) {
  49.                 System.out.print(arr[i][j] ? "*": " ");
  50.             }
  51.             System.out.println("");
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement