Snippets

Ettar Java - while mit ternären Operator

Created by Ettar last modified
public static void main(String[] ARGS){
    Scanner scanner = new Scanner(System.in);
    int gesucht = 3;
    int con=0;
    String output="";

    while(con!=gesucht){
        System.out.println(output);
        con=scanner.nextInt();
        output=con>gesucht ? "Zahl zu groß" : "Zahl zu klein";
    }
    System.out.println("Richtig! Die gesuchte Zahl war "+gesucht);
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.