Name(s): Create a directory for today's lab work; "mkdir lab1" for example. Save this file into this new directory and bring it into a text editor. This file serves as your lab notebook -- paste code, write comments, notes, and questions below each exercise. At the end of the period, mail your notebook to me (lorenz@allspice) and I'll record it as a check mark. I will not grade your lab work, but will answer questions you have noted. If you are working as a team, be sure to list both names at the top so that proper credit may be given. Today's goal is to gain the basics of Java's primitive data-types ("int" and "boolean" in particular) and control flow ("if-then-else", "while", "for"). In doing so, we will pay attention to issues such as initialization, scope of identifiers (variables), and program behavior on exceptional cases (i.e. divide by 0). Time permitting, we will explore how arrays and strings are declared and used in Java. A) Here's a skeleton for a Java program that will suffice for this lab's exercises: class Prog { public static void main(String[] args) { /* local vars go here */ /* code goes here */ } } Change this skeleton to print out "Hello, World"; use 'System.out.println' and change "Prog" to "Hello". Save the program as "hello.java", compile it with "javac hello.java" and run it with "java Hello". B) Write a program that uses a "while" loop to compute the sum of integers from 1 to N. Declare N as an "int" and initialize it to 100 in its declaration. Identify the loop's initialization expression, termination condition, and continuation expression. C) Rewrite exercise B using a "for" loop. D) Add code to the program for exercise C that checks the correctness of the computed result by comparing with N*(N+1)/2. E) Rewrite exercise C to "break" out of the loop when the running sum exceeds 50. F) Rewrite exercise C to sum only the even integers from 1 to N. G) Write a program to average the integers from 1 to N. Before running your code, what do you expect the answer to be? H) Write a simple program to print out a boolean variable and its negation. (Note: System.out.println is _overloaded_ to print many of the primitive types.) I) Exceptional cases: a) Write a program that declares an integer j but does not initialize it. What happens if you try to use j in an expression (or print it out)? b) Write a program that divides an integer by zero and note what happens. When (compile-time or run-time) does this occur? J) Write a program to swap integers i and j if j) { case : case : /* more cases here */ case : default: // optional default case } Write a switch statement to dispatch ten different actions based on the least-significant (rightmost) digit of an integer i. (Recall, "i % 10" will return this digit for integer i.) Is a default case necessary for this task? Why or why not? M) Write a program that declares, initializes and prints out a string. a) modify the program to concatenate the string to itself. (the "+" operator concatenates strings: "a"+"b" gives "ab".) b) modify the program to concatenate a string to an integer. c) modify the program to concatenate a string to a boolean. N) Write a program that declares and allocates an array A of two ints. ("int[] A = new int[2];" will do this.) Do not initialize the array. Write a loop to print out its elements. (The length of an array can always be obtained as "A.length" where A is an array.) Java arrays, like C arrays, are zero-based; that is A[0] is A's first element. What happens if your loop iterates three times and tries to print out A[2] (which wasn't allocated by the above)? O) Modify the previous program to declare, allocate and initialize A to two integers, e.g.: "int[] A = {7,3};" Write code to swap A[0] and A[1] if A[1]