SlideShare a Scribd company logo
1 of 18
CSE110
Principles of Programming
with Java
Lecture 04:
Primitive Data Types
Javier Gonzalez-Sanchez
javiergs@asu.edu
javiergs.engineering.asu.edu
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 2
Summary
class
global
variables
methods statements
instructions
local
variables
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 3
Previously …
§ There are exactly eight primitive data types in Java
§ Four of them represent integers:
byte, short, int, long
§ Two of them represent floating point numbers:
float, double
§ One of them represents characters:
char
§ And one of them represents boolean values:
boolean
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 4
Data Types
The difference between the various numeric primitive
types is their size, and therefore the values they can
store:
Type Size Min Value Max Value
byte 8 bits -128 127
short 16 bits -32,768 32,767
int 32 bits -2^31 2^31 - 1
long 64 bits -2^63 2^63 - 1
float 32 bits +/- 3.4 x 1038 with 7 significant digits
double 64 bits +/- 1.7 x 10308 with 15 significant digits
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 5
char
• A char variable stores a single character from the
Unicode character set
• The Unicode character set uses 16 bits per
character, allowing for 65,536 unique characters
• It is an international character set, containing
symbols and characters from many world
languages
• Character literals are delimited by single quotes:
'a' 'X' '7' '$' ',' 'n'
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 6
Escape Sequences
Escape
Sequence
Meaning
b backspace
t tab
n newline
” double
quote
’ single quote
 backslash
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 7
boolean
• A boolean value – only 2 values, true or false
• The reserved words true and false are the only
valid values for a boolean type
boolean done = false;
boolean success;
success = true;
Arithmetic Expressions
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 9
Summary
class
global
variables
methods statements
local
variables
instructions
expressions
arithmetic
expression
relational
expression
logical
expression
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 10
Expressions
• An expression is a combination of one or more
operands and their operators
• Arithmetic expressions compute numeric results
and make use of the arithmetic operators:
o Addition +
o Subtraction –
o Minus Unary –
o Multiplication *
o Division /
o Remainder %
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 11
Integer Division and Remainder
• Dividend / Divisor = Quotient and Remainder
• Dividend = (Divisor x Quotient) + Remainder
• If both operands to the division operator (/) are
integers, the result is an integer (the fractional part is
discarded)
14 / 3 equals 4 14 % 3 equals 2
8 / 12 equals 0 8 % 12 equals 8
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 12
Test Yourselves
• 17 % 4 =
• -20 % 3 =
• 10 % 5 =
• 3 % 8 =
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 13
Operator Precedence
• Operators have a well-defined precedence which
determines the order in which they are evaluated
• Multiplication, division, and remainder are
evaluated prior to addition, subtraction, and string
concatenation
• Arithmetic operators with the same precedence
are evaluated from left to right
• Parentheses can be used to force the evaluation
order
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 14
Operator Precedence
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 15
String Concatenation
• The plus operator (+) is used to concatenate
(append) strings:
“Hello” + “ World”
• To break a string into two parts in two lines, we need
to close with a double quote and use + sign to
concatenate (append):
System.out.println(“ASU is “
+ “in Arizona”);
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 16
+ operator
• If two operands of + are numbers, it performs an
arithmetic addition.
• If at least one of operands of + is a string, it performs
a string concatenation.
• Examples:
o 2 + 3 will be 5
o 2 + “ apples” will be “2 apples”
o “number ” + 5 will be “number 5”
o “we have “ + 2 + 3 will be “we have 23”
o “we have “ + (2 + 3) will be “we have 5”
Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 17
Homework
Read Chapter 2
CSE110 - Principles of Programming
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2017
Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.

More Related Content

Similar to 201707 CSE110 Lecture 04

Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming languageMegha V
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 

Similar to 201707 CSE110 Lecture 04 (20)

201707 CSE110 Lecture 10
201707 CSE110 Lecture 10 201707 CSE110 Lecture 10
201707 CSE110 Lecture 10
 
201506 CSE340 Lecture 18
201506 CSE340 Lecture 18201506 CSE340 Lecture 18
201506 CSE340 Lecture 18
 
201707 CSE110 Lecture 33
201707 CSE110 Lecture 33  201707 CSE110 Lecture 33
201707 CSE110 Lecture 33
 
201506 CSE340 Lecture 09
201506 CSE340 Lecture 09201506 CSE340 Lecture 09
201506 CSE340 Lecture 09
 
201801 CSE240 Lecture 03
201801 CSE240 Lecture 03201801 CSE240 Lecture 03
201801 CSE240 Lecture 03
 
201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08201506 - CSE340 Lecture 08
201506 - CSE340 Lecture 08
 
201707 CSE110 Lecture 32
201707 CSE110 Lecture 32  201707 CSE110 Lecture 32
201707 CSE110 Lecture 32
 
201506 CSE340 Lecture 07
201506 CSE340 Lecture 07201506 CSE340 Lecture 07
201506 CSE340 Lecture 07
 
201505 CSE340 Lecture 03
201505 CSE340 Lecture 03201505 CSE340 Lecture 03
201505 CSE340 Lecture 03
 
201707 CSE110 Lecture 15
201707 CSE110 Lecture 15   201707 CSE110 Lecture 15
201707 CSE110 Lecture 15
 
Mathematics Basic operations, fractions decimals and percentage.pptx
Mathematics Basic operations, fractions decimals and percentage.pptxMathematics Basic operations, fractions decimals and percentage.pptx
Mathematics Basic operations, fractions decimals and percentage.pptx
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
201707 CSE110 Lecture 03
201707 CSE110 Lecture 03  201707 CSE110 Lecture 03
201707 CSE110 Lecture 03
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
 
201707 CSE110 Lecture 09
201707 CSE110 Lecture 09   201707 CSE110 Lecture 09
201707 CSE110 Lecture 09
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
 
201801 CSE240 Lecture 10
201801 CSE240 Lecture 10201801 CSE240 Lecture 10
201801 CSE240 Lecture 10
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

201707 CSE110 Lecture 04

  • 1. CSE110 Principles of Programming with Java Lecture 04: Primitive Data Types Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 2 Summary class global variables methods statements instructions local variables
  • 3. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 3 Previously … § There are exactly eight primitive data types in Java § Four of them represent integers: byte, short, int, long § Two of them represent floating point numbers: float, double § One of them represents characters: char § And one of them represents boolean values: boolean
  • 4. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 4 Data Types The difference between the various numeric primitive types is their size, and therefore the values they can store: Type Size Min Value Max Value byte 8 bits -128 127 short 16 bits -32,768 32,767 int 32 bits -2^31 2^31 - 1 long 64 bits -2^63 2^63 - 1 float 32 bits +/- 3.4 x 1038 with 7 significant digits double 64 bits +/- 1.7 x 10308 with 15 significant digits
  • 5. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 5 char • A char variable stores a single character from the Unicode character set • The Unicode character set uses 16 bits per character, allowing for 65,536 unique characters • It is an international character set, containing symbols and characters from many world languages • Character literals are delimited by single quotes: 'a' 'X' '7' '$' ',' 'n'
  • 6. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 6 Escape Sequences Escape Sequence Meaning b backspace t tab n newline ” double quote ’ single quote backslash
  • 7. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 7 boolean • A boolean value – only 2 values, true or false • The reserved words true and false are the only valid values for a boolean type boolean done = false; boolean success; success = true;
  • 9. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 9 Summary class global variables methods statements local variables instructions expressions arithmetic expression relational expression logical expression
  • 10. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 10 Expressions • An expression is a combination of one or more operands and their operators • Arithmetic expressions compute numeric results and make use of the arithmetic operators: o Addition + o Subtraction – o Minus Unary – o Multiplication * o Division / o Remainder %
  • 11. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 11 Integer Division and Remainder • Dividend / Divisor = Quotient and Remainder • Dividend = (Divisor x Quotient) + Remainder • If both operands to the division operator (/) are integers, the result is an integer (the fractional part is discarded) 14 / 3 equals 4 14 % 3 equals 2 8 / 12 equals 0 8 % 12 equals 8
  • 12. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 12 Test Yourselves • 17 % 4 = • -20 % 3 = • 10 % 5 = • 3 % 8 =
  • 13. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 13 Operator Precedence • Operators have a well-defined precedence which determines the order in which they are evaluated • Multiplication, division, and remainder are evaluated prior to addition, subtraction, and string concatenation • Arithmetic operators with the same precedence are evaluated from left to right • Parentheses can be used to force the evaluation order
  • 14. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 14 Operator Precedence
  • 15. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 15 String Concatenation • The plus operator (+) is used to concatenate (append) strings: “Hello” + “ World” • To break a string into two parts in two lines, we need to close with a double quote and use + sign to concatenate (append): System.out.println(“ASU is “ + “in Arizona”);
  • 16. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 16 + operator • If two operands of + are numbers, it performs an arithmetic addition. • If at least one of operands of + is a string, it performs a string concatenation. • Examples: o 2 + 3 will be 5 o 2 + “ apples” will be “2 apples” o “number ” + 5 will be “number 5” o “we have “ + 2 + 3 will be “we have 23” o “we have “ + (2 + 3) will be “we have 5”
  • 17. Javier Gonzalez-Sanchez | CSE110 | Summer 2017 | 17 Homework Read Chapter 2
  • 18. CSE110 - Principles of Programming Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2017 Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.