1 Operators and Expressions Instructor: Mainak Chaudhuri

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

Introduction to Programming
This is Java Jeopardy.
1 Administrivia Lecture hours –Monday, Wednesday, Thursday: 11-11:55am, in L7 –Come to the class in time Labs –2pm-5pm, –Monday: A5-A6, Tuesday: A7-A8,
Lecture 1: Comments, Variables, Assignment. Definitions The formal (human-readable) instructions that we give to the computer is called source code The.
Java Planning our Programs Flowcharts Arithmetic Operators.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
11-Jun-15 Just Enough Java. 2 What is Java? Java is a programming language: a language that you can learn to write, and the computer can be made to understand.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Shorthand operators.
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.
1 Please switch off your mobile phones. 2 Data Representation Instructor: Mainak Chaudhuri
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
1 Please switch off your mobile phones. 2 WELCOME To ESC101N: Fundamentals of Computing Instructor: Mainak Chaudhuri
1 Linear and Binary Search Instructor: Mainak Chaudhuri
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
1 Conditionals Instructor: Mainak Chaudhuri
Boolean expressions, part 2: Logical operators. Previously discussed Recall that there are 2 types of operators that return a boolean result (true or.
9/6: Variable Types, Arithmetic Operators, Comparison Operators Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic.
1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 Announcements B7 tutorial today in CS103 –In CSE department –Ask at entry desk for direction to CS103.
Java operatoriai sandbolts/operators.html
Mixing integer and floating point numbers in an arithmetic operation.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Sahar Mosleh California State University San MarcosPage 1 Data Types and Operators.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Authors: Peter Cappello Damon Chastain Matthew Urtnowski Course:CECS 541 Instructor: Dr. Michael Hoffman Date:Fall 2010.
Programs That Calculate. Arithmetic Expressions +addition -subtruction *multiplication /division  Order of Operations BEDMAS (brackets, exponentiation,
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
1 Printing characters : Revisited class printcharacter{ public static void main(String arg[]){ char grade=‘A’; System.out.println(grade);// prints A System.out.println((int)grade);
1 Conditionals Instructor: Mainak Chaudhuri
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CompSci 230 S Programming Techniques
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Lecture 3: Method Parameters
Elementary Programming
Introduction to Computer Science / Procedural – 67130
Lecture 2: Data Types, Variables, Operators, and Expressions
2.5 Another Java Application: Adding Integers
Computer Programming Methodology Introduction to Java
Java operatoriai
Operators and Expressions
OPERATORS (1) CSC 111.
Java so far Week 7.
Variables & Data Types Java.
Recap Week 2 and 3.
class PrintOnetoTen { public static void main(String args[]) {
Chapter 2: Java Fundamentals
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
In this class, we will cover:
Just Enough Java 17-May-19.
Instructor: Mainak Chaudhuri
Presentation transcript:

1 Operators and Expressions Instructor: Mainak Chaudhuri

2 Announcements Tuesday is our independence day –It is a holy day –The tutorial will meet on Saturday –The Tuesday lab will meet on Saturday Wednesday is also a holiday –No lab and no class on Wednesday

3 Agenda Your first programs in Java Arithmetic operators Expressions

4 Printing on monitor /* Example of multiline comment; This is our first Program */ class printcoursename{ public static void main(String arg[]){ // This prints name of the course (single line comment) System.out.println("This course is ESc101N"); }

5 Printing on monitor /* Example of multiline comment; This is our second Program. Will print the same thing in a different way. */ class printcoursename{ public static void main(String arg[]){ // This prints name of the course (single line comment) System.out.println("This ” + “course ” + “is ” + “ESc101N”); }

6 Printing numbers class printnumber { public static void main (String args[]){ // Notice that I can use args also // because it is a variable name and can be // anything. int var1; // Declaration var1 = 124; // Operator and expression System.out.println("Value of var1 is: "+var1); }

7 Operators Arithmetic operators +, -, *, /, % –Addition: a+b –Subtraction: a-b –Multiplication: a*b –Division: a/b (what is this? Find out in lab) –Remainder: a%b Assignment operator = Comparison operators: >, =, <=, ==, !=

8 Expressions An expression is a statement involving operators and variables or constants Example: x = a + b; // Add a and b and put the // result in x Example: int x = 6; // Declaration and // initialization int y = x; y = y + 1; // Same as y += 1; // Same as y++; –Two new operators: +=, ++ –More operators: -=, *=, /=, --

9 Expressions More examples class SomeThing { public static void main (String args[]) { int x, y; boolean z, w; x = 10; y = 12; z = (x > y); w = (y >= x); System.out.println(“z: ” + z + “,” + “w: ” +w); }

10 Expressions More examples class SomeThing { public static void main (String args[]) { int x, y; boolean z, w; x = 10; y = 10; z = (x == y); w = (y != x); System.out.println(“z: ” + z + “,” + “w: ” +w); }

11 Logical operators Not: ! AND: && OR: || Examples: int x = 12; boolean isTwoDigit = ((x >= 10) && (x < 100)); boolean isMultipleOfSix = ((x%6)==0); boolean isOdd = !((x%2)==0); boolean isLessThan100Perfect = ((x==6) || (x==28)); boolean isTwoDigit = (10 <= x < 100); [Wrong!]