
import java.util.Scanner;

class Sep21 {

	public static void main(String[] args) {

		//declare an array of ints
		int[] arr = new int[10];

		//read values from keyboard
		Scanner kb = new Scanner(System.in);
		System.out.println("Enter 10 integers");
		
		for(int i = 0; i < arr.length; i++) {
			arr[i] = kb.nextInt();
		}

		printArray(arr);

		int[] arr2 = new int[10];
		
		// copy contents of arr into arr2
		for(int i = 0; i < arr.length; i++) {
			arr2[i] = arr[i];
		}

		printArray(arr2);

		// careful with ; symbols - below it creates block of code for for-loop.
		// the block with println is not associated with the for-loop and
		// prints just once.	
		for(int i = 0; i < arr.length; i++) ; 
		
		{
			System.out.println("Hello");
		}

		/* infinite while-loop
		while(true) {
			System.out.println("Hello");
		}
		*/

		/* Infinite for-loop
		for(;;) {
			System.out.println("Hello");
		}
		*/		

		// To debug problem, print values of variables used in computation 
		// below I add print statement inside for-loop

		int sum = 0;	
		for(int i = 0; i < arr.length; i++) { 
			sum = sum + arr[i];
			//System.out.println("sum: " + sum);  //debug statement
		}
		System.out.println("sum: " + sum);

		// ?: operator

		int length = 0;
		if (arr.length > 10) {
			length = arr.length;
		}
		else {
			length = 5;
		}
		System.out.println("length: " + length);

		length = (arr.length > 10) ? arr.length : 5;
	}
	
	public static void printArray(int[] foo) {
		for(int i = 0; i < foo.length; i++) {
			System.out.print(foo[i] + " ");
		}
		System.out.println();
	}
	
}

// out of bounds


