Ivan18113

Алгоритми - Тема 15 (Обхождане на матрица)

Feb 27th, 2021 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.*;
  2. public class Cuks {
  3.     static int count = 0;
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         System.out.print("Matrix Size: " );
  8.         int number = scan.nextInt();
  9.         int[][] matrix = new int[number][number];
  10.         calculate(matrix,0 ,0);
  11.         System.out.println("Tracks: "+count);
  12.  
  13.     } //end of main
  14.  
  15.  
  16.     public static void calculate(int[][] matrix, int row, int colum){
  17.         if(row == matrix.length -1&& colum == row){
  18.             count++;
  19.         }
  20.        
  21.         if(row < matrix.length - 1){
  22.             calculate(matrix,row+1,colum);
  23.         }
  24.        
  25.         if(colum < matrix.length -1){
  26.             calculate(matrix,row,colum+1);
  27.         }
  28.        
  29.     } //end of calculate
  30.  
  31.  
  32. } //end of class
Add Comment
Please, Sign In to add comment