Midterm Study Exercises:

Here is a study fill in the blank sheet of the basic Java syntax you need to know

Write the following programs in both Alice and Java:

1. Ask a user for 2 numbers. Put both numbers into variables. Switch the values in the variables. Print out the first variable value and then the second one.

2. Ask a user for one number, and then add4 to it 5 times, telling the user the new value each time. To accomplish this: Write and use a function add4 to take a given number parameter and add 4 to it.

3. All of your homework exercises are also excellent study exercises, including the CodeLab exercises.

Simpler programs:

4. Ask the user for a number and print the absolute value of the number using Math.abs. (This ensures you know how to use scanner, and Math.abs.)

5. Write a program that sets 2 variables and then prints the highest of the two variables.

6. Fill in the main method for this program:
public class myTest
{
   public static void main()
   {
         String mood = "happy";
         int age = 3;
         // call the method printMood passing it mood and age

         // change the mood to sad and x to 2

          // call the method printMood passing it mood and age
   
     }
    public static void printMood (String myMood, int myAge)
    {
           System.out.println("I am " + myAge + "years old and I am " + myMood);
    }
}