Thebaro
22-04-2008, 14:30
Buonasera, sto cercando di imparare java... ma ho dei problemi:
vi posto il listato:
il problema è che inserendo un numero pari il programma esce... mi aiutate a risolvere il problema ?
grazie.
package paridis;
import java.io.BufferedReader;
import java.io.InputStreamReader;;
public class testy
{
public testy()
{
}
public static void main(String args[])
{
int NumeroUtente = -1;
boolean Pari = true;
while(NumeroUtente != 0)
{
try
{
InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader stdin = new BufferedReader( isr );
System.out.println("Inserire un numero (0 per uscire): ");
NumeroUtente = Integer.parseInt(stdin.readLine());
System.out.println("Hai inserito: " + NumeroUtente);
}
catch(Exception e){}
while(NumeroUtente > 0)
{
NumeroUtente = NumeroUtente - 2;
if(NumeroUtente < 0)
Pari = false;
else
Pari = true;
}
if(Pari == true)
System.out.println("Il numero è pari");
else
System.out.println("Il numero è dispari");
}
}
}
vi posto il listato:
il problema è che inserendo un numero pari il programma esce... mi aiutate a risolvere il problema ?
grazie.
package paridis;
import java.io.BufferedReader;
import java.io.InputStreamReader;;
public class testy
{
public testy()
{
}
public static void main(String args[])
{
int NumeroUtente = -1;
boolean Pari = true;
while(NumeroUtente != 0)
{
try
{
InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader stdin = new BufferedReader( isr );
System.out.println("Inserire un numero (0 per uscire): ");
NumeroUtente = Integer.parseInt(stdin.readLine());
System.out.println("Hai inserito: " + NumeroUtente);
}
catch(Exception e){}
while(NumeroUtente > 0)
{
NumeroUtente = NumeroUtente - 2;
if(NumeroUtente < 0)
Pari = false;
else
Pari = true;
}
if(Pari == true)
System.out.println("Il numero è pari");
else
System.out.println("Il numero è dispari");
}
}
}