Skip to content

Instantly share code, notes, and snippets.

@andrelramos
Last active November 24, 2015 17:32
Show Gist options
  • Select an option

  • Save andrelramos/2fd77d1265cb57065874 to your computer and use it in GitHub Desktop.

Select an option

Save andrelramos/2fd77d1265cb57065874 to your computer and use it in GitHub Desktop.
Exemplo do projeto em java do Lucão
import java.util.Scanner;
public class Lugares {
public static void main(String args[]) {
boolean lugares[][] = new boolean[4][12]; //Matriz 4 x 12
//Setando todos lugares como false
for(int fileira = 0; fileira <= 3; fileira++) { //Percorrendo as 4 fileiras da matriz
for(int lugar = 0; lugar <= 11; lugar++) { //Percorrendo cada cadeira dentro da fileira
lugares[fileira][lugar] = false;
}
}
while(true) { //Loop infinito para manter o programa em funcionamento
//Recebendo input do usuário
Scanner in = new Scanner(System.in);
System.out.println("Digite uma fileira entre 1 e 4: ");
int fileiraInput = in.nextInt()-1;
System.out.println("Digite uma cadeira entre 1 e 12: ");
int cadeiraInput = in.nextInt()-1;
//Verificando se o lugar está vazio
if(!lugares[fileiraInput][cadeiraInput]) { //Se o lugar estiver vazio
lugares[fileiraInput][cadeiraInput] = true; //Oculpando o lugar
System.out.println("Lugar reservado com sucesso.");
} else {
System.out.println("Este lugar não está vazio.");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment