Ir ao conteúdo
  • Cadastre-se

Lukas_Sperandio

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

posts postados por Lukas_Sperandio

  1. Boa tarde, o meu programa está dando erro nas linhas 45, 48, 52, 100, 103, e 106 (todos eles são o mesmo erro) e gostaria de saber se alguém poderia me ajudar com isso

     

    OBS: eu nn sei resolver o problema que o site fala quando você vai enviar, falando que precisa do "<>" 

     

     

    <

    package Aula20;

     

    import java.util.Scanner;

     

    import javax.xml.namespace.QName;

     

    public class Ex06 {

     

        public static void main(String[] args) {

     

            Scanner scan = new Scanner(System.in);

     

            String[][] tabuleiro = new String[3][3];

     

            boolean vitoria = true;

            int jogador = 1;

            int posicaoX = 0;

            int posicaoY = 0;

            String vencedor = "";

            int jogadas = 0;

     

            System.out.println("Jogador 1 - X");

            System.out.println("Jogador 2 - O");

     

            lacoWhile: while (vitoria) {

                if (jogador == 1) {

                    System.out.println("Vez do jogador 1");

                    System.out.println("Entre com a posição (X, Y)");

                    posicaoX = Integer.parseInt(scan.nextLine());

                    posicaoY = Integer.parseInt(scan.nextLine());

                    while (tabuleiro[posicaoX][posicaoY] != null || tabuleiro[posicaoX][posicaoY] == "O") {

                        System.out.println("Posição inválida, entre com os valores novamente");

                        System.out.println("Entre com a posição (X, Y)");

                        posicaoX = Integer.parseInt(scan.nextLine());

                        posicaoY = Integer.parseInt(scan.nextLine());

                    }

                    tabuleiro[posicaoX][posicaoY] = "X";

                    jogador = 2;

                    jogadas++;

                }

     

                if (jogadas >= 4) {

                    int i = 0;

                    int j = 0;

                    if((tabuleiro[i][j] && tabuleiro[i+1][j] && tabuleiro[i+2][j])   == "X"){

                        vencedor = "O jogador 1 venceu!";

                        break lacoWhile;

                    }else if((tabuleiro[i][j] && tabuleiro[i][j+1] && tabuleiro[i][j+2])   == "X"){

                        vencedor = "O jogador 1 venceu!";

                        break lacoWhile;

                    }

                    else if((tabuleiro[i][j] && tabuleiro[i+1][j+1] && tabuleiro[i+1][j+2])   == "X"){

                        vencedor = "O jogador 1 venceu!";

                        break lacoWhile;

                    }

                }

     

                for (int i = 0; tabuleiro.length > i; i++) {

                    for (int j = 0; tabuleiro[i].length > j; j++) {

                        if (tabuleiro[i][j] != null) {

                            System.out.print(tabuleiro[i][j] + " |  ");

                        } else {

                            System.out.print("  |  ");

                        }

                    }

                    System.out.println();

                }

     

                if (jogador == 2) {

                    System.out.println("Vez do jogador 2");

                    System.out.println("Entre com a posição (X, Y)");

                    posicaoX = Integer.parseInt(scan.nextLine());

                    posicaoY = Integer.parseInt(scan.nextLine());

                    while (tabuleiro[posicaoX][posicaoY] != null || tabuleiro[posicaoX][posicaoY] == "X") {

                        System.out.println("Posição inválida, entre com os valores novamente");

                        System.out.println("Entre com a posição (X, Y)");

                        posicaoX = Integer.parseInt(scan.nextLine());

                        posicaoY = Integer.parseInt(scan.nextLine());

                    }

                    tabuleiro[posicaoX][posicaoY] = "O";

                    jogador = 1;

                    jogadas++;

                }

     

                for (int i = 0; tabuleiro.length > i; i++) {

                    for (int j = 0; tabuleiro[i].length > j; j++) {

                        if (tabuleiro[i][j] != null) {

                            System.out.print(tabuleiro[i][j] + " |  ");

                        } else {

                            System.out.print("  |  ");

                        }

                    }

                    System.out.println();

                }

     

                if (jogadas >= 4) {

                    int i = 0;

                    int j = 0;

     

                    if((tabuleiro[i][j] && tabuleiro[i+1][j] && tabuleiro[i+2][j])   == "O"){

                        vencedor = "O jogador 2 venceu!";

                        break lacoWhile;

                    }else if((tabuleiro[i][j] && tabuleiro[i][j+1] && tabuleiro[i][j+2])   == "O"){

                        vencedor = "O jogador 2 venceu!";

                        break lacoWhile;

                    }

                    else if((tabuleiro[i][j] && tabuleiro[i+1][j+1] && tabuleiro[i+1][j+2])   == "O"){

                        vencedor = "O jogador 2 venceu!";

                        break lacoWhile;

                    }

                }

            }

            System.out.println("FIM DE JOGO!!!!!!");

            System.out.println(vencedor);

        }

     

    }

     

    >

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...