Class 5 Mon 1/28 Comp 110 Variables - quick review Program 3 Branches Simple Compound statements Quick review of variables --- Java is a strongly typed language --- each variable is assigned a data type: int n1; --- you can only assign legal values of the specified type to the variable. Ex. n1 = "Comp110" is not legal. --- Our most common data types int String boolean double --- a data type is i) a set of values ii) a set of operations on those values Simple branch if( x > 5 ) System.out.println("A"); A branch is a fork in the road, or, more formally, a change in the flow of control. Default flow of control is: top to bottom, left to right. Just like reading a book. In each branch we ask a question. Each question must be simple enough to have a true or false answer. The answer determines which group of Java statements (i.e. which branch) is executed by the computer. Integers comparisons = question we can ask in Java 3 == x x != z x > y String comparison requies 'equals'. Ex: if(str.equals("comp110")) SOP("rocks"); A compound statement bundles together multiple statements if(str.equals("comp110")) { SOP("rocks"); SOP(" totally"); } Nested branch if(raining) Top up else if(really cold) Top up else Top down Compound condition if(raining || really cold) Top up else Top down