Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UpsideDown {
- public static void main (String[] args){
- Scanner in = new Scanner(System.in);
- boolean teste = false;
- int [][] matriz = new int[9][9];
- for (int i = 0; i < 9;i++){
- for (int j = 0;j < 9;j++){
- matriz[i][j] = in.nextInt();
- }
- }
- if (teste){
- boolean aux = caminho(matriz,0,0);
- System.out.println("Welcome to the Upside Down.");
- }
- else {
- System.out.println("RUN!");
- }
- }
- public static boolean caminho (int matriz [][],int i,int j){
- boolean resposta = false;
- //caso base
- if (i==9 && j ==9){
- resposta = true;
- }
- else {
- //SUL
- if (matriz[i + 1][j] == 1) {
- if (i < 8) {
- caminho(matriz, i + 1, j);
- }
- }
- //LESTE
- else if (matriz[i][j + 1] == 1) {
- if (j < 8) {
- caminho(matriz, i, j + 1);
- }
- }
- //NORTE
- else if (matriz[i][j] == 1) {
- if (i > 1) {
- caminho(matriz, i - 1, j);
- }
- }
- //OESTE
- else if (matriz[i][j] == 1) {
- if (j > 1) {
- caminho(matriz, i, j - 1);
- }
- }
- }
- return resposta;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement