Code Refresher Test #1 Topics:

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
Operator. Assignation (=). The assignation operator serves to assign a value to a variable. a = 5; It is necessary to emphasize that the assignation operation.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
2440: 211 Interactive Web Programming Expressions & Operators.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CSC 204 Programming I Loop I The while statement.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Wrapper Classes and ArrayList Mrs. C. Furman 9/15/2008.
Research Topics in Computational Science. Agenda Survey Overview.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Operators.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
1 CS161 Introduction to Computer Science Topic #6.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Lecture 10. Review (Char) Character is one of primitive data types of variable (such as integer and double) –Character variable contains one character.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
LESSON 3 Expressions, Statements, & Operators. STATEMENTS A statement Controls the sequence of execution Evaluates an expression Does nothing (the null.
7 - Programming 7J, K, L, M, N, O – Handling Data.
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Lecture 3 Java Operators.
Operators And Expressions
University of Central Florida COP 3330 Object Oriented Programming
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
University of Central Florida COP 3330 Object Oriented Programming
User input We’ve seen how to use the standard output buffer
Learning About the Loop Structure (continued)
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
All the Operators 22-Nov-18.
Lists in Python.
An Introduction to Java – Part I, language basics
All the Operators 4-Dec-18.
C Operators, Operands, Expressions & Statements
Logical Operations In Matlab.
Chapter 2: Java Fundamentals
Chapter 2 Programming Basics.
All the Operators 6-Apr-19.
Arrays in Java.
All the Operators 13-Apr-19.
Java: Variables, Input and Arrays
Comparing Python and Java
OPERATORS in C Programming
First Semester Review.
OPERATORS in C Programming
Presentation transcript:

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

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

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

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

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

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

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

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!

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(); }

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

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(); }

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