import java.util.Scanner;

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

		Scanner kb = new Scanner(System.in);

		// Determine how many instances of the letter l is in the string "hello"

		String str = "hello";
		int len = str.length();  // get length of string
	
		int count = 0;
		for(int i = 0; i < len; i++) {
			char c = str.charAt(i);

			if (c == 'l') {
				count++;
			}
		}
		System.out.println("number of l: " + count);	
	
		// Some helpful methods in the Character wrapper class

		char c = str.charAt(0);
		boolean flag = Character.isDigit(c);
		flag = Character.isLetter(c);

		// Practice calling methods

		System.out.println("please enter a decimal");
		double input1 = kb.nextDouble();

		System.out.println("please enter a decimal");
		double input2 = kb.nextDouble();

		double area = computeArea(input1, input2);

		System.out.println("area: " + area);

		System.out.println("please enter an integer");
		int n = kb.nextInt();

		int fact = factorial(n);
		System.out.println("factorial: " + fact);
	
		/* 
			Remember to strip the \n off the scanner stream
			if reading a string after a numeric type.
		*/

		while(true) {
			System.out.println("enter an integer");
			int x = kb.nextInt();
			kb.skip("\\R");

			System.out.println("enter a string");
			String str2 = kb.nextLine();
			System.out.println("str: [" + str2 + "]");

			if (str2.equals("exit")) {
				break;
			}	

		}

	}
	
	/* 
		Write a method named computeArea that has two
		double parameters representing the lengths of the
		sides of a rectangle.  The method returns the 
		area of the rectangle.
	*/

	static double computeArea(double x, double y) {
		return (x * y);
	}

	/* 
		Write a method named factorial that takes an integer n
		as an argument and returns n!
	*/

	/*
		Error: when the user enters a negative number, 
		0 is returned.
	*/

	static int factorial(int n) {

		if (n < 1) {
			return 0;
		}

		int total = 1;
		for(int i = n; i > 1; i--) {
			total = total * i;
		}
		return total;
	}

}




// end of file
