import java.util.Random;

/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target="_blank">Strutture condizionali</a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */
class Main {
	public static void followFlow() {
		boolean sentinel = true;
		Random random = new Random();

		// if-else

		if (sentinel)
			System.out.println("if -> " + sentinel);
		else
			System.out.println("else -> " + sentinel);

		// nested-if

		if ((random.nextInt() % 2) == 0) {
			// in presenza di nested-if mai omettere { ... }
			if ((new Random().nextInt() % 2) == 0) 
				System.out.println("nested-if");
		}

		// if-else-if

		if ((random.nextInt() % 2) == 0)
			System.out.println("if");
		else if ((random.nextInt() % 2) == 0)
			System.out.println("else-if");
		else
			System.out.println("else");

		// switch

		int option = random.nextInt(5);

		switch (option) {
		case 0: {
			System.out.println(option);
			break;
		}
		case 1: {
			System.out.println(option);
			break;
		}
		case 2: {
			System.out.println(option);
			break;
		}

		default: {
			System.out.println("default");
		}
		}
	}
	
    public static void main(String[] args) {
		// Unit test - strutture condizionali
		followFlow();
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: