CS Programming I: Branches

Size: px
Start display at page:

Download "CS Programming I: Branches"

Transcription

1 CS Programming I: Branches Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2018 TopHat Sec 3 (AM) Join Code: TopHat Sec 4 (PM) Join Code:

2 Boolean Statements

3 1/33 Booleans Primitive boolean b; Values: true or false Wrapper class: Boolean

4 2/33 Boolean Expressions An expression that evaluates to a boolean Ie true or false

5 2/33 Boolean Expressions An expression that evaluates to a boolean Ie true or false Comparison Operators Binary (expr1 oper expr2 ): == : Equal to!= : Not equal to > : Greater than < : Less than >= : Greater than or equal <= : Less than or equal

6 2/33 Boolean Expressions An expression that evaluates to a boolean Ie true or false Logical Operators Unary (oper expr ):! : Logical NOT Binary (expr1 oper expr2 ): && : Logical AND : Logical OR Don t confuse with the bitwise operators: &,, and ˆ

7 3/33 Operator Precedence Level Operator Description Associativity higher ( <expression> ) grouping with parentheses left to right [ ] ( ) array index, method call, member left to right access (dot operator) ++ post-increment, post-decrement left to right ! pre-increment, unary plus/minus, right to left logical negation (type) new casting and creating object right to left * / % multiplication, division, modulus left to right addition, subtraction, concatenation left to right < <= > >= instanceof relational and Java s instanceof left to right operator ==!= equality left to right && conditional AND (short-circuits) left to right conditional OR (short-circuits) left to right lower? : ternary conditional right to left = += -= *= /= %= assignment, arithmetic (compound) right to left assignment

8 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

9 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

10 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

11 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

12 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

13 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

14 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

15 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

16 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

17 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

18 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

19 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

20 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

21 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

22 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

23 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

24 4/33 Truth Tables a b a b a b a b a Logic Rules AND (&&, &) True only if both operands are true OR (, ) True if either operand is true XOR (ˆ) Exclusive OR; True if one (but not both) operand(s) is true NOT (!) Flips the truth value

25 5/33 TopHat Question 1 If A is 1 and B is 1, what is!a B? a 1 b 0

26 6/33 Bitwise Operations Performs the logical operations on each of the corresponding bits of the operands Bitwise Operators Binary (expr1 oper expr2 ): & Bitwise AND Bitwise OR ˆ Bitwise XOR

27 6/33 Bitwise Operations Performs the logical operations on each of the corresponding bits of the operands Eg 7 & 5 = 5 Consider the bits: Bitwise Operators 111 & Binary (expr1 oper expr2 ): & Bitwise AND Bitwise OR ˆ Bitwise XOR

28 7/33 TopHat Question 2 What is 7 5? a 12 b 7 c 5 d 3

29 Comparing References

30 8/33 Reference Comparison Equality Operator (==) Generally, the equality operator compares the values of two variables Recall: value of a reference type is the referral information

31 Reference Comparison Equality Operator (==) Generally, the equality operator compares the values of two variables Recall: value of a reference type is the referral information Stack 6 Heap Integer i = 6; Integer j = 6; Integer k = new Integer (6); k j i 6 8/33

32 Reference Comparison Equality Operator (==) [Resp: Inequality Operator (!=)] Generally, the equality operator compares the values of two variables Recall: value of a reference type is the referral information Stack 6 Heap Integer i = 6; Integer j = 6; Integer k = new Integer (6); k j i 6 8/33

33 9/33 TopHat Question 3 What is the output? Integer i = 5; Integer j = 5; Integer k = new Integer (5); System out print (i == j); System out print (j == k);

34 10/33 Comparing Values of Primitive Wrappers Integer i = 6; Integer j = 5; Integer k = new Integer ( 6); int m = 5; Instance Methods for Comparison equals(otherobj) True if values of the objects are equal False otherwise Eg iequals(k) // true

35 10/33 Comparing Values of Primitive Wrappers Integer i = 6; Integer j = 5; Integer k = new Integer ( 6); int m = 5; Instance Methods for Comparison equals(otherobj) True if values of the objects are equal False otherwise Eg iequals(k) // true compareto(otherobj) 0 if equal, negative if less than otherobj, and positive if greater than otherobj Eg icompareto(j) // +ve

36 Comparing Values of Primitive Wrappers Integer i = 6; Integer j = 5; Integer k = new Integer ( 6); int m = 5; Instance Methods for Comparison equals(otherobj) True if values of the objects are equal False otherwise Eg iequals(k) // true compareto(otherobj) 0 if equal, negative if less than otherobj, and positive if greater than otherobj Eg icompareto(j) // +ve Other Comparison Operators (In)Equality exception: j == m // true Other operators work as expected: <, <=, >, >= 10/33

37 11/33 TopHat Question 4 What is the output? Scanner sc = new Scanner (" foo "); String s = " foo "; String t = sc next (); System out print (s == t);

38 12/33 String Comparison Only Instance Methods equals(otherstr) compareto(otherstr)

39 12/33 String Comparison Only Instance Methods equals(otherstr) compareto(otherstr) Lexicographical Comparison Starting from index 0 and compare each pair of characters at index x according to the following rules: 1 The character with the smaller Unicode value is considered smaller lexicograpically 2 No character is smaller than an existing character (Eg "foo" is smaller than "foobar")

40 12/33 String Comparison Only Instance Methods equals(otherstr) compareto(otherstr) equalsignorecase(otherstr) comparetoignorecase(otherstr) Lexicographical Comparison Starting from index 0 and compare each pair of characters at index x according to the following rules: 1 The character with the smaller Unicode value is considered smaller lexicograpically 2 No character is smaller than an existing character (Eg "foo" is smaller than "foobar")

41 13/33 TopHat Question 5 Arrange these words in lexicographical order (smallest to largest): a Javascript b C c Java d C++ e C#

42 Conditional Statements

43 14/33 If Statement if ( cond ) { truestatement ; lasttruestatement ;

44 14/33 If Statement Control Flow if ( cond ) { truestatement ; lasttruestatement ; cond true True Stmt Block Following statements false

45 15/33 If-Else Statement if ( cond ) { truestatement ; lasttruestatement ; else { falsestatement ; lastfalsestatement ;

46 15/33 If-Else Statement if ( cond ) { truestatement ; lasttruestatement ; else { falsestatement ; lastfalsestatement ; Control Flow true True Stmt Block cond Following statements false False Stmt Block

47 16/33 TopHat Question 6 What is printed out in be following code block: boolean tobe = false ; if( tobe! tobe ) { System out print (" Tautology "); else { System out print (" Contradiction ");

48 17/33 TopHat Question 7 What is the boolean expression to complete the following code? Assume that i is an int variable Replace?????? in the code with the appropriate boolean expression if(?????? ) { System out println ( i + " is divisible by 3"); else { System out println ( i + " is not divisible by 3");

49 18/33 TopHat Question 8 What is the output? int i = 3; if ((i = 5) > 4) { System out print ("a"); else { System out print ("b");

50 19/33 If-Else If Statement Ending Else if ( cond1 ) { truestatements1 ; else if ( cond2 ) { truestatements2 ; else { allfalsestatements ;

51 19/33 If-Else If Statement Ending Else Control Flow if ( cond1 ) { truestatements1 ; else if ( cond2 ) { truestatements2 ; True 1 Stmt Block True 2 Stmt Block true true cond1 false cond2 All false else { allfalsestatements ; Following statements Else Stmt Block

52 20/33 If-Else If Statement No Ending Else if ( cond1 ) { truestatements1 ; else if ( cond2 ) { truestatements2 ; else if ( condn ) { truestatementsn ;

53 20/33 If-Else If Statement No Ending Else Control Flow if ( cond1 ) { truestatements1 ; else if ( cond2 ) { truestatements2 ; else if ( condn ) { truestatementsn ; True 1 Stmt Block True 2 Stmt Block true true True N Stmt Block cond1 Following statements cond2 true false condn false

54 21/33 Multiple Ifs if ( cond1 ) { truestatements1 ; if ( cond2 ) { truestatements2 ; if ( condn ) { truestatementsn ;

55 21/33 Multiple Ifs Control Flow if ( cond1 ) { truestatements1 ; if ( cond2 ) { truestatements2 ; if ( condn ) { truestatementsn ; True 1 Stmt Block True 2 Stmt Block True N Stmt Block true true true cond1 cond2 false condn false Following statements

56 If-Else If vs Multiple Ifs Control Flow If-Else If Control Flow Multiple Ifs True 1 Stmt Block True 2 Stmt Block true true cond1 false cond2 True 1 Stmt Block True 2 Stmt Block true true cond1 cond2 false True N Stmt Block true Following statements condn false True N Stmt Block true condn false Following statements 22/33

57 23/33 TopHat Question 9 What does the following code print? int v1 = 3, v2 = 6; if (v1 + 2 < v2) System out print (" tic "); else if (v1 + 4 < v2) System out print (" tac "); else if (v1 + 4 > v2) System out print (" toe ");

58 24/33 TopHat Question 10 What does the following code print? int v1 = 3, v2 = 6; if (v1 + 2 < v2) System out print (" tic "); if (v1 + 4 < v2) System out print (" tac "); if (v1 + 4 > v2) System out print (" toe ");

59 case const2 : case2statements ; break ; default : defstatements ; break ; 25/33 Switch Statements switch ( expr ) { case const1 : case1statements ; break ;

60 Switch Statements Control Flow switch ( expr ) { case const1 : case1statements ; break ; case const2 : case2statements ; break ; default : defstatements ; break ; Case 1 Stmt Block Case 2 Stmt Block true true expr == const1 expr == const2 Following statements false No match Default Block 25/33

61 Switch Statements Control flow depends on break; switch ( expr ) { case const1 : case1statements ; break ; case const2 : case2statements ; break ; default : defstatements ; break ; Control Flow Case 1 Stmt Block Case 2 Stmt Block true true expr == const1 expr == const2 Following statements false No match Default Block 25/33

62 Switch Statements Control flow depends on break; switch ( expr ) { case const1 : case1statements ; case const2 : case2statements ; break ; default : defstatements ; break ; Control Flow Case 1 Stmt Block Case 2 Stmt Block true no break; true expr == const1 expr == const2 Following statements false No match Default Block 25/33

63 26/33 Switch Statements Keys Rules Finds the first match going from the top to the bottom in order Fall through A case without a break will fall through to the next case s statements

64 26/33 Switch Statements Keys Rules Finds the first match going from the top to the bottom in order Fall through A case without a break will fall through to the next case s statements Good Practices Only use fall though when the cases execute the same code Generally, it is best to always have a default case at the end

65 27/33 If-Else if and Switch Statements if (i == 1) { System out println (" one "); else if (i == 2) { System out println (" two "); else { System out println (" Not 1 or 2");

66 If-Else if and Switch Statements if (i == 1) { System out println (" one "); else if (i == 2) { System out println (" two "); else { System out println (" Not 1 or 2"); switch (i) { case 1: System out println (" one "); break ; case 2: System out println (" two "); break ; default : System out println (" Not 1 or 2"); break ; 27/33

67 TopHat Question 11 What does the following code print? int month = 8; switch ( month ) { case 1: System out print (" January "); break ; case 2: System out print (" February "); break ; case 3: System out print (" March "); break ; case 4: System out print (" April "); break ; case 5: System out print ("May "); break ; case 6: System out print ("June "); break ; case 7: System out print ("July "); break ; case 8: System out print (" August "); break ; case 9: System out print (" September "); break ; case 10: System out print (" October "); break ; case 11: System out print (" November "); break ; case 12: System out print (" December "); break ; default : System out print (" Invalid month "); break ; 28/33

68 TopHat Question 12 What does the following code print? int month = 8; switch ( month ) { case 1: System out print (" January "); case 2: System out print (" February "); case 3: System out print (" March "); case 4: System out print (" April "); case 5: System out print (" May "); case 6: System out print (" June "); case 7: System out print (" July "); case 8: System out print (" August "); case 9: System out print (" September "); case 10: System out print (" October "); case 11: System out print (" November "); case 12: System out print (" December "); break ; default : System out print (" Invalid month "); break ; 29/33

69 30/33 Ordinal Abbreviation Exercise Write a method that takes an integer as input and returns a string with the integer converted to an abbreviated ordinal Ie 1 becomes 1st, 2 becomes 2nd, 3 becomes, 3rd, etc

70 Using Eclipse

71 Eclipse Eclipse Integrated development environment (IDE) that we will use in the course In 2017, 405% use Eclipse (48% use IntelliJ) a In 2016, 482% use Eclipse (436% use IntelliJ) b a Source: b Source: 31/33

72 Eclipse Eclipse Integrated development environment (IDE) that we will use in the course In 2017, 405% use Eclipse (48% use IntelliJ) a In 2016, 482% use Eclipse (436% use IntelliJ) b a Source: b Source: Installing and Using Installation: Tutorials: resources/eclipse-tutorial/ 31/33

73 32/33 Style Guide Examples: http: //pagescswiscedu/~cs200/resources/framejava http: //pagescswiscedu/~cs200/resources/circlejava Key Elements File Comment Header Class Comment Header Method Comment Header Good names with proper formatting Proper use of whitespace

74 33/33 Further Reading COMP SCI 200: Programming I zybookscom, 2015 zybook code: WISCCOMPSCI200Fall2018 Chapter 4 Branches

75 Appendix References Appendix

76 Appendix References References

77 Appendix References 34/33 Image Sources I

CS Programming I: Branches

CS Programming I: Branches CS 200 - Programming I: Branches Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Boolean Statements

More information

CS Programming I: Arrays

CS Programming I: Arrays CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics

More information

CS Programming I: Primitives and Expressions

CS Programming I: Primitives and Expressions CS 200 - Programming I: Primitives and Expressions Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code:

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

CS Programming I: Using Objects

CS Programming I: Using Objects CS 200 - Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Binary

More information

CT 229. Java Syntax 26/09/2006 CT229

CT 229. Java Syntax 26/09/2006 CT229 CT 229 Java Syntax 26/09/2006 CT229 Lab Assignments Assignment Due Date: Oct 1 st Before submission make sure that the name of each.java file matches the name given in the assignment sheet!!!! Remember:

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

CS Programming I: Using Objects

CS Programming I: Using Objects CS 200 - Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 Binary

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

COMP6700/2140 Operators, Expressions, Statements

COMP6700/2140 Operators, Expressions, Statements COMP6700/2140 Operators, Expressions, Statements Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU 3 March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Operators,

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

More information

CS Programming I: ArrayList

CS Programming I: ArrayList CS 200 - Programming I: ArrayList Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 ArrayLists

More information

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

CONDITIONAL EXECUTION: PART 2

CONDITIONAL EXECUTION: PART 2 CONDITIONAL EXECUTION: PART 2 yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Review: The if-else statement The switch statement A look

More information

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( ) Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.

More information

CS Programming I: Programming Process

CS Programming I: Programming Process CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455

More information

CS Programming I: Programming Process

CS Programming I: Programming Process CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2019 TopHat Sec 3 (AM) Join Code: 560900 TopHat Sec 4 (PM) Join Code: 751425

More information

CT 229 Java Syntax Continued

CT 229 Java Syntax Continued CT 229 Java Syntax Continued 29/09/2006 CT229 Lab Assignments One Week Extension for Lab Assignment 1. Due Date: Oct 8 th Before submission make sure that the name of each.java file matches the name given

More information

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators. Lecture 3 COP 3014 Spring January 16, 2018 Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz) SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

More information

CS Programming I: Programming Process

CS Programming I: Programming Process CS 200 - Programming I: Programming Process Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624

More information

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

CS Programming I: Exceptions

CS Programming I: Exceptions CS 200 - Programming I: Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code: 165455 Command-Line Arguments

More information

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

More information

CS Programming I: Inheritance

CS Programming I: Inheritance CS 200 - Programming I: Inheritance Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Inheritance

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Java Basic Programming Constructs

Java Basic Programming Constructs Java Basic Programming Constructs /* * This is your first java program. */ class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World! ); A Closer Look at HelloWorld 2 This

More information

Operators in java Operator operands.

Operators in java Operator operands. Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

CS Programming I: Exceptions

CS Programming I: Exceptions CS 200 - Programming I: Exceptions Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Command-Line

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Java enum, casts, and others (Select portions of Chapters 4 & 5) Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

More information

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS OPERATORS Review: Data values can appear as literals or be stored in variables/constants Data values can be returned by method calls Operators: special symbols

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups: JAVA BASIC OPERATORS http://www.tuto rialspo int.co m/java/java_basic_o perato rs.htm Copyrig ht tutorialspoint.com Java provides a rich set of operators to manipulate variables. We can divide all the

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Computer Programming, I. Laboratory Manual. Experiment #3. Selections Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #3

More information

Chap 6 - Introduction to HDL (b)

Chap 6 - Introduction to HDL (b) Design with Verilog Chap 6 - Introduction to HDL (b) Credit to: MD Rizal Othman Faculty of Electrical & Electronics Engineering Universiti Malaysia Pahang Ext: 6036 Language Elements 1. Operators There

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

Expressions & Assignment Statements

Expressions & Assignment Statements Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements

More information

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

CS1150 Principles of Computer Science Boolean, Selection Statements

CS1150 Principles of Computer Science Boolean, Selection Statements CS1150 Principles of Computer Science Boolean, Selection Statements Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 Math Center https://www.uccs.edu/mathcenter/schedules

More information

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java

Object-Oriented Programming. Topic 2: Fundamental Programming Structures in Java Electrical and Computer Engineering Object-Oriented Topic 2: Fundamental Structures in Java Maj Joel Young Joel.Young@afit.edu 8-Sep-03 Maj Joel Young Java Identifiers Identifiers Used to name local variables

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Chapter 6 Primitive types

Chapter 6 Primitive types Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question

More information

More Programming Constructs -- Introduction

More Programming Constructs -- Introduction More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

More information

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

Logical and Bitwise Expressions

Logical and Bitwise Expressions Logical and Bitwise Expressions The truth value will set you free. 1 Expression Constant Variable Unary Operator Binary Operator (expression) Function Invocation Assignment: = Prefix: +, -, ++, --,!, ~

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

More information

Conditionals and Loops

Conditionals and Loops Conditionals and Loops Conditionals and Loops Now we will examine programming statements that allow us to: make decisions repeat processing steps in a loop Chapter 5 focuses on: boolean expressions conditional

More information

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7. Expressions and Assignment Statements ISBN Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

More information

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved. Chapter 4: Expressions Chapter 4 Expressions 1 Chapter 4: Expressions Operators Expressions are built from variables, constants, and operators. C has a rich collection of operators, including arithmetic

More information

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14

Chapter 4: Making Decisions. Copyright 2012 Pearson Education, Inc. Sunday, September 7, 14 Chapter 4: Making Decisions 4.1 Relational Operators Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than or equal to

More information

Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

More information

Lecture 3 Operators MIT AITI

Lecture 3 Operators MIT AITI Lecture 3 Operators MIT AITI - 2004 What are Operators? Operators are special symbols used for mathematical functions assignment statements logical comparisons Examples: 3 + 5 // uses + operator 14 + 5

More information

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators: http://www.tutorialspoint.com/ruby/ruby_operators.htm RUBY OPERATORS Copyright tutorialspoint.com Ruby supports a rich set of operators, as you'd expect from a modern language. Most operators are actually

More information

A flow chart is a graphical or symbolic representation of a process.

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Expressions and Precedence. Last updated 12/10/18

Expressions and Precedence. Last updated 12/10/18 Expressions and Precedence Last updated 12/10/18 Expression: Sequence of Operators and Operands that reduce to a single value Simple and Complex Expressions Subject to Precedence and Associativity Six

More information

CS Programming I: File Input / Output

CS Programming I: File Input / Output CS 200 - Programming I: File Input / Output Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624

More information

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Chapter 7. Expressions and Assignment Statements

Chapter 7. Expressions and Assignment Statements Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

More information

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web Web programming The PHP language Our objective Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web Access data inserted by users into HTML forms Interact

More information

COMP 110 Introduction to Programming. What did we discuss?

COMP 110 Introduction to Programming. What did we discuss? COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 Today Announcements

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators ARITHMATIC OPERATORS The assignment operator in IDL is the equals sign, =. IDL uses all the familiar arithmetic operators

More information

ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

More information

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

Chapter 4: Conditionals and Loops

Chapter 4: Conditionals and Loops Chapter 4: Conditionals and Loops CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 4: Conditionals and Loops CS 121 1 / 69 Chapter 4 Topics Flow

More information

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee 1 0 1 0 Foundation Topics 1 0 Chapter 1 - Introduction to Programming 1 1 Systems Development Life Cycle N/A N/A N/A N/A N/A N/A 1-8 12-13 1 2 Bloodshed Dev-C++ 5 Compiler/IDE N/A N/A N/A N/A N/A N/A N/A

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

More information

Chapter 4: Control Structures I

Chapter 4: Control Structures I Chapter 4: Control Structures I Java Programming: From Problem Analysis to Program Design, Second Edition Chapter Objectives Learn about control structures. Examine relational and logical operators. Explore

More information

Chapter 6. More Complex Conditionals. 6.1 Nested Conditionals

Chapter 6. More Complex Conditionals. 6.1 Nested Conditionals 56 Chapter 6 More Complex Conditionals Despite the initial simplicity of if/else statements as introduced in Chapter 5, things can get interesting when if/else statements are composed of other if/else

More information

Arithmetic-logic units

Arithmetic-logic units Arithmetic-logic units An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the heart of a processor you could say that everything else in the CPU is there

More information

ECEN 468 Advanced Logic Design

ECEN 468 Advanced Logic Design ECEN 468 Advanced Logic Design Lecture 26: Verilog Operators ECEN 468 Lecture 26 Operators Operator Number of Operands Result Arithmetic 2 Binary word Bitwise 2 Binary word Reduction 1 Bit Logical 2 Boolean

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information