Duvida urgente!

1 resposta
M

Bom minha duvida é a seguinte:se o valor for incorreto eu quero retornar a “a” e “b” (int) para por outro valor…ou seja não pedir para executar novamente!!!

import javax.swing.JOptionPane;

public class JOSystem{

}

public static void main (String args [] ){

int a =Integer.parseInt(JOptionPane.showInputDialog(valor 1));

int b =Integer.parseInt(JOptionPane.showInputDialog(valor 2));

if (a <= 0 || b <=0 )

System.out.println(“Valor incorreto”);
}

[b][/b]

1 Resposta

S

Tenta ae!!
[b]

public class JOSystem{

public static void main (String args [] ){

int a=0,b=0;

while((a<=0) || (b<=0)){

try

{

a =Integer.parseInt(JOptionPane.showInputDialog(valor 1));

b =Integer.parseInt(JOptionPane.showInputDialog(valor 2));

if (a <= 0 || b <=0 )
throw new Exception(“Valor Incorreto!!!”);

}

catch(Exception e)

{

System.out.println(e.getMessage());

a==0;b==0;

}

}

}}
[/b]

Criado 28 de abril de 2005
Ultima resposta 28 de abr. de 2005
Respostas 1
Participantes 2