import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.io.File;

class Apr23 {
	public static void main(String[] args) {
		// do-while

		Scanner kb = new Scanner(System.in);
		boolean showMenu = true;

		do {
			System.out.println("Menu");
			System.out.println("1. compute n!");
			System.out.println("2. exit");

			int option = kb.nextInt();
			if (option == 1) {
				computeNFactorial();
			}
			else {
				showMenu = false;
			}
		} while (showMenu);

		// ?:

		System.out.print("Do you want to continue? (yes,no) ");
		String response = kb.next();
		if (response.equals("yes")) {
			showMenu = true;
		}
		else {
			showMenu = false;
		}
	
		// equivalent one liner
		showMenu = (response.equals("yes")) ? true : false;	

		// swap
		
		int a = 7;
		int b = 12;
		System.out.printf("a:%d b:%d\n", a, b);

		int temp = a;
		a = b;
		b = temp;

		System.out.printf("a:%d b:%d\n", a, b);

		// Writing to a new file
		PrintWriter pw = null;
		try {
			pw = new PrintWriter("cam.txt");
		}
		catch (FileNotFoundException e) {
			System.out.println("Cannot write to file");
			System.exit(0);
		}

		pw.printf("Dear Cam, \n\tWe are writing to inform you...\n");

		pw.close();

		Scanner fin = null;
		try {
			fin = new Scanner(new File("cam.txt"));
		}
		catch (FileNotFoundException e) {
			System.out.println("Cannot read file");
			System.exit(0);
		}
		// fin.useDelimiter(...);
		while(fin.hasNext()) {
			String line = fin.nextLine();
			System.out.println(line);
		}
		



	}

	static void computeNFactorial() {
		Scanner kb = new Scanner(System.in);
		System.out.print("Enter integer: ");
		int n = kb.nextInt();
		int v = n;
		long result = 1;
		while(v > 1) {
			result = result * v;
			v--;
		}
		System.out.printf("%d! = %d\n", n, result);
	}

}
