Estou com um problema no array

3 respostas
B
import java.util.Scanner;

public class aviao_voador_com_asas {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int[] numero_voo = new int[2];
		String[] origem_voo = new String[2];
		String[] destino_voo = new String[2];
		int[] numero_lugares = new int[2];
		int menu_fazer, n_voo_pesq, consulta_opc;
		int x;
		String consulta_string;
		for (x = 0; x < 2; x++) {
			System.out.print("\nNúmero do Vôo: ");
			numero_voo[x] = s.nextInt();
			System.out.print("Origem : ");
			origem_voo[x] = s.next();
			System.out.print("Destino : ");
			destino_voo[x] = s.next();
			System.out.print("Quantidade de lugares: ");
			numero_lugares[x] = s.nextInt();

		}
		do {
			System.out.println(" \n:::MENU:::");
			System.out.println("1  consultar");
			System.out.println("2  efetuar reserva");
			System.out.println("3  sair");
			menu_fazer = s.nextInt();
			if (menu_fazer == 3 || menu_fazer != 1 && menu_fazer != 2) {
				System.exit(0);
			}
			if (menu_fazer == 1) {
				System.out.println(":::CONSULTA:::");
				System.out.println("\n1 - Por número de voo:");
				System.out.println("2 - Por origem:");
				System.out.println("3 - Por destino:");
				consulta_opc = s.nextInt();
				if (consulta_opc == 1) {
					System.out.print("Vôo desejado: ");
					n_voo_pesq = s.nextInt();
					for (x = 0; x <= 1; x++) {
						if (n_voo_pesq == numero_voo[x]) {
							System.out.println("Dados: ");
							System.out.println("Número do vôo: " + n_voo_pesq);
							System.out.println("Origem : " + origem_voo[x]);
							System.out.println("Destino : " + destino_voo[x]);
						}
					}
				}
				if (consulta_opc == 2) {
					System.out.print("Digite a origem do voo: ");
					consulta_string = s.next();
					for (x = 0; x <= 1; x++) {
						if (consulta_string.equalsIgnoreCase(origem_voo[x])) {
							System.out.println("Dados: ");
							System.out.println("Número do vôo: "
									+ numero_voo[x]);
							System.out.println("Origem : " + consulta_string);
							System.out.println("Destino : " + destino_voo[x]);
						}
					}
				}
				if (consulta_opc == 3) {
					System.out.println("Destino: ");
					String pd = s.next();
					for (x = 0; x <= 1; x++) {
						if (pd.equals(destino_voo[x])) {
							System.out.println("Dados: ");
							System.out.println("Número do vôo: "
									+ numero_voo[x]);
							System.out.println("Origem : " + origem_voo[x]);
							System.out.println("Destino : " + pd);
						}
					}
				}
			}
			if (menu_fazer == 2) {
				System.out.print("Número do vôo: ");
				int conf_voo = s.nextInt();
				for (x = 0; x < 1; x++) {
					if (conf_voo == numero_voo[x] && numero_lugares[x] > 0) {
						System.out.println("RESERVA CONFIRMADA");
						numero_lugares[x] = numero_lugares[x] - 1;
						break;
					} else if (conf_voo == numero_voo[x]
							&& numero_lugares[x] == 0) {
						System.out.println("VOO LOTADO");
						break;
					} else {
						System.out.println("VOO INESXISTENTE");
						break;
					}
				}
			}
		} while (menu_fazer != 3 && (menu_fazer == 2 || menu_fazer == 1));
	}
}
Estou com uma certa dificuldade em fazer o programa reconhecer, quando vou fazer a consulta por exemplo, cadastrei o voo "1" e o voo "2", acaba aparecendo voo inexistente, sendo que ele existe. Não sei aonde esta o erro :S

3 Respostas

Rodrigo_Sasaki

O que tem de errado nesse for?for (x = 0; x < 1; x++) {

lina

Oi,

Filho, poderia ser mais especifico? Em qual array?

Tchauzin!

B

acho que no numero_voo, pois quando vou consultar, ele nao acha.
Tem como pesquisar dentro de um array, sem ter que percorrer todo ele com um for?

Criado 10 de outubro de 2012
Ultima resposta 10 de out. de 2012
Respostas 3
Participantes 3