This question already has an answer here:
- Ternary Operators Java 5 answers
- What is the Java ?: operator called and what does it do? 14 answers
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