Advertisement
Boyan5

Тема 15

Feb 26th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class theme15 {
  4.     public static void main(String[] args) {
  5.                 // взимаме числото за размера
  6.                 System.out.print("Enter Number: ");
  7.                 Scanner scan = new Scanner(System.in);
  8.                 // слагаме го в интове
  9.                 int temp = scan.nextInt();
  10.                 int r = temp;
  11.                 int l = temp;
  12.                 temp = 0;
  13.                 int n = 0; int rr = 0; int c = 0;
  14.                 int [][] m = new int [r][l];
  15.                 // фора проверява дали излизаме извън размерите
  16.                 int i = 0;
  17.                 while (i < r){
  18.                     if (rr == c && rr == r){break;}
  19.                     c = i;
  20.                     while (c < r) {
  21.                         c++;
  22.                         while (rr < r) { rr++;
  23.                         } n++;
  24.                     }
  25.                 }
  26.                 n = 0;c = 0;rr = 0;
  27.                 // намира първо пътите, които отиват надолу и надясно
  28.                 for (int a = 0; a < r; a++) {
  29.                     if (rr == c && rr == r) {
  30.                         temp = n-2;
  31.                         System.out.println("Down right tracks: "+ temp);break;}
  32.                     while(c < r) {
  33.                         c++;
  34.                         rr++; n += 2;}}
  35.                 n = 0;
  36.                 c = 0;
  37.                 rr = 0;
  38.                 // след това тези надолу и надясно единствено
  39.                 for (int a = 0; a < r; a++) {
  40.                     if (rr == c && rr == r) {
  41.                         temp = n-2;
  42.                         System.out.println("Down and right only tracks: " + temp);
  43.                         break;
  44.                     }
  45.                     while(c <= 2) {
  46.                         n++;
  47.                         c++;
  48.                         while (rr < r) {
  49.                             n++;
  50.                             rr++;
  51.                         }
  52.                     }
  53.                 }
  54.                 n = 0;
  55.                 c = 0;
  56.                 rr = 0;
  57.                 // и на края проверява колко пътя има надясно
  58.                 for (int a = 0; a < r; a++) {
  59.                     if (rr == c && rr == r) {
  60.                         temp = n-2;
  61.                         System.out.println("right tracks " + temp);break;}
  62.                     while (c < a) {
  63.                         c++;
  64.                         n++;
  65.                         if (c == a) {
  66.                             while (rr < a) {
  67.                                 rr++;
  68.                                 n++;
  69.                             }
  70.  
  71.                         }
  72.                         // след което свършва кода, и се принтират в конзолата
  73.                     }
  74.                 }
  75.     }
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement