Advertisement
wellison1

Untitled

Oct 13th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class UpsideDown {
  3.     public static  void main (String[] args){
  4.         Scanner in = new Scanner(System.in);
  5.         int [][] matriz = new int[10][10];
  6.         for (int i = 0; i < 10;i++){
  7.             for (int j = 0;j < 10;j++){
  8.                 matriz[i][j] = in.nextInt();
  9.             }
  10.  
  11.         }
  12.     int teste = 0;
  13.         teste = caminho(matriz,0,0);
  14.             if (teste==1){
  15.                 System.out.println("Welcome to the Upside Down.");
  16.  
  17.             } else{
  18.                 System.out.println("RUN!");
  19.             }
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.     }
  27.     public static int caminho (int matriz [][],int i,int j){
  28.         if(i==9 & j==9) {
  29.             return 1;
  30.         }
  31.         // SUL
  32.         if(i+1<=9 & matriz[i+1][j]==1) {
  33.             matriz[i+1][j]=0;
  34.             return caminho(matriz, i+1, j);
  35.         }
  36.         //LESTE
  37.         else if(i+1<=9 & matriz[i][j+1]==1) {
  38.             matriz[i][j+1]=0;
  39.             return caminho(matriz, i, j+1);
  40.         }
  41.         //NORTE
  42.         else if(i-1>=0 & matriz[i-1][j]==1) {
  43.             matriz[i-1][j]=0;
  44.             return caminho(matriz, i-1, j);
  45.         }
  46.         //OESTE
  47.         else if( j-1>=0 & matriz[i][j-1]==1) {
  48.             matriz[i][j-1]=0;
  49.             return caminho(matriz, i, j-1);
  50.         }
  51.         return 5;
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement