I wrote a code which is kind of an interview. It asks you how old you are and what your gender is. For some reason the .exe gets terminated after it prints out the second question. Why is that? How can I fix it?
I checked the syntax but can't seem to find the mistake.
import java.io.IOException;
public class Abfrage {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
char Geschlecht;
System.out.println("Wie ist dein Geschlecht? M oder W?");
Geschlecht = (char) System.in.read();
int Alter;
System.out.println("Wie ist dein Alter?");
Alter = (int) System.in.read();
if (Alter >= 18 && Alter <= 100)
{
System.out.println("Du bist volljaehrig, herzlichen Glueckwunsch!");
}
}
}
It prints out this string ("Wie ist dein Alter?") and after that it gets terminated. I can't put in my age(number) which is the question asked in the println.
I expect it to let me put in my age, and if I am between 18 and 100 it should tell me "congrats on being an adult." (its not finished there are more if/else)
Edit: I tried adding an if else statement. When I run the .exe:
if (Alter >= 18 && Alter <= 100)
{
System.out.println("Du bist volljaehrig, herzlichen Glueckwunsch!");
}
else if (Alter >= 0 && Alter <= 17);
{
System.out.println("Du bist leider minderjaehrig mein Kind");
}
When I did this, it just prints out the else if println "Du bist leider minderjaehrig mein Kind" after the question "Wie ist dein Alter?". It terminates after that.