dimanche 27 août 2017

What is the meaning of ? and : in if statement? [duplicate]

This question already has an answer here:

I'm lost at int result(int result = (input == 0 ? 0 : (input < 0 ? -1 : 1));

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int input = console.nextInt();
        int result = (input == 0 ? 0 : (input < 0 ? -1 : 1));
        System.out.println(result);
    }
}

Aucun commentaire:

Enregistrer un commentaire