Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code Refresher Test #1 Topics:

Similar presentations


Presentation on theme: "Code Refresher Test #1 Topics:"— Presentation transcript:

1 Code Refresher Test #1 Topics:
Variable: int, double, boolean Operators: Arithmetic, Assignment Logical, and Relational Control: If, Else If, Else Loops: For, While Method: Parameters, Returns Arrays: Array, ArrayList

2 Variables int, double, boolean
int: Stores whole numbers double: Stores fractional numbers boolean: Stores true or false values

3 Arithmetic Operators Addition: + Subtraction: - Multiplication: *
Division: / Modulo: % Calculates the remainder after division!

4 Assignment Operators Assignment: = Compound Assignment Operators:
Add&Assign: += Sub&Assign: -= Mult&Assign: *= Div&Assign: /= Mod&Assign: %=

5 Postfix / Prefix Operators
Note: Also called increment/decrement x++ Postfix add one ++x Prefix add one y- - Postfix subtract one - -y Prefix subtract one

6 Relational Operators Equal To: == Not Equal To: != Greater Than: >
Greater Than or Equal To: >= Less Than: < Less Than or Equal To: <=

7 Logical Operators AND: && OR: || NOT: !
Both expressions must be true for the result to be true! OR: || Either expression must be true for the result to be true! NOT: ! True is flipped to false, false is flipped to true

8 Control Statements if(expression) { code(); }
code() is executed if the expression is true else if(expression) { code(); } Tacked on to an if statement, checks expression else { code(); } Else means everything else, NO expression!

9 Loops For, While For loops are used to execute a group of statements a set number of times for(int i = 0; i < 10; i++) { System.out.println(i); } While loops are used to execute a group of statements as long as a condition is true while(expression == true) { code(); }

10 Methods Methods are groups of statements that can be called at any point in a program. You can send data to methods (parameters), and receive data from a method (return). public static int methodName(boolean b) { code(); } This method returns a value of type int If you want to return nothing, use void This method takes in one boolean parameter and names it b Call methods by writing their name and sending them parameters

11 Arrays Arrays are used to store a set number of elements. They are accessible via indexes. Note: Indexes start at zero in Java. int[] myArray = new int[10]; // stores ten integers myArray.length; // returns the length Use a for-loop to access each element for(int i = 0; i < myArray.length; i++) { code(); }

12 import java.util.ArrayList; ArrayLists
ArrayLists are used to store a list of data. They are also accessible via indexes. Note: ArrayLists start out empty with zero elements. ArrayList<Integer> myList = new ArrayList<Integer>(); myList.add(4); // adds the number 4 to the list myList.get(0); // gets the first element in the list myList.remove(0); // removes the first element myList.size(); // returns the size of the list


Download ppt "Code Refresher Test #1 Topics:"

Similar presentations


Ads by Google