Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class theme15 {
- public static void main(String[] args) {
- // взимаме числото за размера
- System.out.print("Enter Number: ");
- Scanner scan = new Scanner(System.in);
- // слагаме го в интове
- int temp = scan.nextInt();
- int r = temp;
- int l = temp;
- temp = 0;
- int n = 0; int rr = 0; int c = 0;
- int [][] m = new int [r][l];
- // фора проверява дали излизаме извън размерите
- int i = 0;
- while (i < r){
- if (rr == c && rr == r){break;}
- c = i;
- while (c < r) {
- c++;
- while (rr < r) { rr++;
- } n++;
- }
- }
- n = 0;c = 0;rr = 0;
- // намира първо пътите, които отиват надолу и надясно
- for (int a = 0; a < r; a++) {
- if (rr == c && rr == r) {
- temp = n-2;
- System.out.println("Down right tracks: "+ temp);break;}
- while(c < r) {
- c++;
- rr++; n += 2;}}
- n = 0;
- c = 0;
- rr = 0;
- // след това тези надолу и надясно единствено
- for (int a = 0; a < r; a++) {
- if (rr == c && rr == r) {
- temp = n-2;
- System.out.println("Down and right only tracks: " + temp);
- break;
- }
- while(c <= 2) {
- n++;
- c++;
- while (rr < r) {
- n++;
- rr++;
- }
- }
- }
- n = 0;
- c = 0;
- rr = 0;
- // и на края проверява колко пътя има надясно
- for (int a = 0; a < r; a++) {
- if (rr == c && rr == r) {
- temp = n-2;
- System.out.println("right tracks " + temp);break;}
- while (c < a) {
- c++;
- n++;
- if (c == a) {
- while (rr < a) {
- rr++;
- n++;
- }
- }
- // след което свършва кода, и се принтират в конзолата
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement