Dúvida boba

5 respostas
M

Galera do guj,

Tenho uma dúvida boba em um código que não estou conseguindo executar
corretamente.

no código abaixo

import javax.swing.JOptionPane;

public class PodeOuNaoPode {

	public static void main(String[] args){
		
		String idade;
		int idade1;
	
	idade = JOptionPane.showInputDialog("Informe sua idade");
	idade1 = Integerparseint(idade);
	
	if (idade1 < 18){
		
		JOptionPane.showMessageDialog(null, "Não pode entrar!");
		//System.out.println("Não pode entrar");
		
	}else{
		JOptionPane.showMessageDialog(null, "Pode entar!");
		//System.out.println("Pode entrar");
	}
	
}

	private static int Integerparseint(String idade) {
		// TODO Auto-generated method stub
		return 0;
	}
}

a única resposta que sai é a primeira ou seja “não pode entrar”, alguém poderia me informar por que?

Obrigado

5 Respostas

T
private static int Integerparseint(String idade) {
 		// TODO Auto-generated method stub
 		return 0;
 	}

Por que é que você definiu esta função? Remova esta função, substitua por “Integer.parseInt”, e tente novamente.

P

private static int Integerparseint(String idade) { // TODO Auto-generated method stub return 0; }
Seu metodo sempre ira retornar 0, e no if

if (idade1 &lt 18){

e por isso a resposta sempre sera

utilize Integer.parseInt()

java_Regi

a parte do seu método.

idade1 = Integerparseint(idade);

está errada.
não precisa fazer o metodo Integerparseint.
ele já existe.

precisa do PONTO > . <

idade1 = Integer.parseint(idade);

e coloque assim o IF

if(idade1 <= 18 ){ ..... }

espero ter ajudado.
até

M

Valeu cara!!

Na mosca.

M

Valeu thingol !!!

Na mosca

Criado 15 de março de 2007
Ultima resposta 15 de mar. de 2007
Respostas 5
Participantes 4