package lezione04; public class Slide28 { public static void main(String[] args) { /* provate a cambiare i valri delle variabili * per sperimentare quali "rami" dei vari if * il programma percorre */ int x = 0; int y = 2; int z = 1; if (x == y) { System.out.println("1) x is equal to y"); } else { System.out.println("1) x is NOT equal to y"); } // blocco 2), equivalente al blocco 3) if (x == y) { if (x == z) { System.out.println("2) x, y, and z are all equals"); } else { System.out.println("2) x and y are equals but z is not"); } } else { if (x == z) { System.out.println("2) x and z are equals but y is not"); } else { if (y == z) { System.out.println("2) y and z are equals but x is not"); } else { System.out.println("2) x, y, and z are all different"); } } } // blocco 3), equivalente al blocco 2) if (x == y && x == z) { System.out.println("3) x, y, and z are all equals"); } else if (x == y && x != z) { System.out.println("3) x and y are equals but z is not"); /* Notate l'istruzione sotto: scrivere * if () { * ... * } else { * if () { * ... * } * } * equivale a scrivere * if () { * ... * } else if () { * ... * } * } */ } else if (x != y && x == z) { System.out.println("3) x and z are equals but y is not"); } else if (y == z){ System.out.println("3) y and z are equals but x is not"); } else { System.out.println("3) x, y, and z are all different"); } } }