import java.util.Scanner;

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

		int x = 10;
		float f = 3.5f;
		double d = 3.5;
		char c = 'a';
		String s = "hi";

		System.out.printf("x:%-5d f:%-5.1f d:%-5.1f c:%-5c s:%-5s \n", x, f, d, c, s);

		System.out.println("x:" + x + ", d:" + d + ", c:" + c + ", s:" + s); 

		int[] arr = {1,2,3};

		for(int i : arr) {
			System.out.printf("%d ", i);
		}
		System.out.println();

		// values after formatted string can be any expression that evaluates to the particular placeholder type.
		System.out.printf("sum: %f\n", f + d);

		// .# between % and placeholder type char specifies percision (# digits after .)
		System.out.printf("sum: %.2f\n", f + d);

		// # between % and placeholder type char specifies width of value displayed
		// padded on right by default
		System.out.printf("sum: %5d\n", x);
		
		// -# between % and placeholder type char specifies width of value displayed
		// with padding on the left 
		System.out.printf("sum: %5d\n", x);

		// Can save a formatted string
		String str = String.format("sum: %5f\n", f + d);
		System.out.print(str); 
	
		// quiz prep question
		int result = getElement(arr, 1);
		System.out.println(result);

	}
	
	static int getElement(int[] a, int i) {
		return a[i];
	}
		
}
