Skip to content

Instantly share code, notes, and snippets.

@hpai1989
Created September 23, 2013 05:02
Show Gist options
  • Save hpai1989/6666599 to your computer and use it in GitHub Desktop.
Save hpai1989/6666599 to your computer and use it in GitHub Desktop.
prelab 4
//1. Create a variable called test of type boolean and assign the variable the value true.
boolean test = true
//2.Create a variable called a of type int and assign the variable the value 5.
int a = 5
/*3.Type in an if statement that adds 1 to a if test has value true and subtracts 1 from a if test has value false.
Helpful hint: The DrJava interactions pane will evaluate an expression after you hit the return key if what you have typed in is a valid expression. To keep the interactions pane from evaluating your if statement prematurely, either type the entire statement in one line or place the statement inside braces { }*/
if (test == true) {
a + 1;}
else { a - 1;}
//4.Type a to see the current value of a. If you did everything correctly, it should be 6.
//5.Now assign test to have value false and a to have value 5.
//6.Type in the same if statement as above and test the value for a. It should have value 4.
//7.Type in a method called add that takes two parameters, an int parameter called x, and an int parameter called y, and returns an int. add should return x+y. You can type the method directly into the Interactions pane. You do not need to create a class.
//8.Test add by calling add with two numbers and verifying that the sum is returned. (Remember to omit the semicolon on this step so that the return value will be displayed.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment