
import java.util.Scanner;

class Feb19 {
	public static void main(String[] args) {

		Scanner kb = new Scanner(System.in);

		int sum = 0;
		double count = 0;
		int input = 1;

		System.out.println("Enter integers, 0 to stop");
		while(input != 0) {
			input = kb.nextInt();

			if(input != 0) {
				sum += input;  // sum = sum + input
				count++;
			}
		}
		double mean = sum / count;
		System.out.printf("Mean: %f \n", mean);

		// break;  - breaks you out of current loparity

		System.out.println("Enter integers, 0 to stop");
		while(true) {
			input = kb.nextInt();
			if (input == 0) {
				break;
			}

			System.out.printf("%d ", input);
		}
		System.out.println();
		
		// continue; - changes execution to tparity of current loparity

		System.out.println("Enter integers, 0 to stop");
		while(true) {
			input = kb.nextInt();
			
			if (input == 0) {
				break;
			}

			if (input % 2 == 1) {
				continue;
			}

			System.out.printf("%d ", input);
		}
		System.out.println();

		// ?: parity operator

		System.out.println("Enter integer");
		input = kb.nextInt();

		String parity = "";
		if (input % 2 == 0) {
			parity = "even";
		}
		else {
			parity = "odd";
		}
		System.out.printf("Parity: %s\n", parity);

		parity = (input % 2 == 0) ? "even" : "odd";	
		System.out.printf("Parity: %s\n", parity);

		// another example
		System.out.println("Enter go or stop");
		String command = kb.next();

		boolean stop = (command.equals("stop")) ? true : false;

		// switch statements

		System.out.println("Enter integer");
		input = kb.nextInt();

		switch(input) {
			case 0:
				System.out.println("zero");
				break;
			case 1:
				System.out.println("one");
				break;
			default:
				System.out.println("all other cases");
		}

		// You can switch on variables of String, int, char types

		// menu system with switch
		char choice = '\0';
		while(true) {
			System.out.println("(a) add\n");
			System.out.println("(r) remove\n");
			System.out.println("(e) exit\n");
			System.out.print("Enter choice: ");

			choice = kb.next().charAt(0);

			switch(choice) {
				case 'a':
					System.out.println("adding...");
					break;
				case 'r':
					System.out.println("removing...");
					break;
				case 'e':
					System.out.println("exit...");
					break;	
				default:
					System.out.println("invalid entry");
			}

			if (choice == 'e') {
				break;
			}
		}
	}
}
