Computational Expression

Size: px
Start display at page:

Download "Computational Expression"

Transcription

1 Computational Expression Scanner, Increment/Decrement, Conversion Janyl Jumadinova 17 September, 2018 Janyl Jumadinova Computational Expression 17 September, / 11

2 Review: Scanner The Scanner class in the java.util package is a simple text scanner which can parse primitive types and strings. We can use the Scanner class to get the input. Janyl Jumadinova Computational Expression 17 September, / 11

3 Review: Scanner The Scanner class in the java.util package is a simple text scanner which can parse primitive types and strings. We can use the Scanner class to get the input. We must first create an instance of the Scanner as: Scanner name = new Scanner (System.in); to read from the terminal, Janyl Jumadinova Computational Expression 17 September, / 11

4 Review: Scanner The Scanner class in the java.util package is a simple text scanner which can parse primitive types and strings. We can use the Scanner class to get the input. We must first create an instance of the Scanner as: Scanner name = new Scanner (System.in); to read from the terminal, or Scanner name = new Scanner (File filename); to read from the file, where File filename = new File ( input.txt ); and name is the name you choose for your instance of the Scanner Janyl Jumadinova Computational Expression 17 September, / 11

5 Scanner Methods next() : get the next word (token) as a String nextline() : get a line of input as a String nextint() : get an integer nextdouble() : get a double value nextfloat() : get a float value Janyl Jumadinova Computational Expression 17 September, / 11

6 Memory Concepts Variable names correspond to locations in the computer s memory. Janyl Jumadinova Computational Expression 17 September, / 11

7 Memory Concepts Variable names correspond to locations in the computer s memory. Every variable has: - a name, - a type, - a size, - a value Janyl Jumadinova Computational Expression 17 September, / 11

8 Memory Concepts Variable names correspond to locations in the computer s memory. Every variable has: - a name, - a type, - a size, - a value first = input.nextint(); stores whatever the user types into the location associated with first. Janyl Jumadinova Computational Expression 17 September, / 11

9 Memory Concepts Whenever a value is placed in a memory location, it replaces whatever was there before. This includes keyboard input (such as first = input.nextint()) and assignment statements (such as sum = first + second). Janyl Jumadinova Computational Expression 17 September, / 11

10 Conversion Widening - from byte to short, int, long, float or double - from short to int, long, float, double - from char to int, long, float, double - from int to long, float, double - from long to float, double - from float to double Janyl Jumadinova Computational Expression 17 September, / 11

11 Conversion Narrowing - should be avoided! - from byte to char - from short to byte, char - from char to byte, short - from int to byte, short, char - from long to byte, short, char, int - from float to byte, short, char, int, long - from double to byte, short, char, int, long, float Janyl Jumadinova Computational Expression 17 September, / 11

12 Conversion Assignment: grade = A Promotion: total/count, where total is a floating point value and count is an integer - Occurs automatically, count is promoted to a floating point value Casting: grade = (int) total - Java operator: type name in parentheses - Casting converts floating point value total into an integer, truncating any fractional part. Janyl Jumadinova Computational Expression 17 September, / 11

13 Increment and Decrement Operators ++: adds 1 to any value count ++ same as count=count+1 prefix form: ++count postfix form: count++ --: subtracts 1 from any value count -- same as count=count-1 prefix form: --count postfix form: count-- Janyl Jumadinova Computational Expression 17 September, / 11

14 Increment and Decrement Operators ++: adds 1 to any value count ++ same as count=count+1 prefix form: ++count postfix form: count++ --: subtracts 1 from any value count -- same as count=count-1 prefix form: --count postfix form: count-- total = count ++; vs. total = ++count; Janyl Jumadinova Computational Expression 17 September, / 11

15 Increment and Decrement Operators += (-=, *=,..): combine basic operation with assignment count += num same as count=count+num Janyl Jumadinova Computational Expression 17 September, / 11

16 Google Style Exercise and Directory Organization Google Java Style Guide Janyl Jumadinova Computational Expression 17 September, / 11

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

More information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Data Conversion & Scanner Class

Data Conversion & Scanner Class Data Conversion & Scanner Class Quick review of last lecture August 29, 2007 ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev Numeric Primitive Data Storing

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Computational Expression

Computational Expression Computational Expression, Math Class, Wrapper Classes Janyl Jumadinova 18 February, 2019 Janyl Jumadinova Computational Expression 18 February, 2019 1 / 8 The Random class is part of the java.util package

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 02 Data Types and Statements MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Data Types Arithmetic

More information

Reading Input from Text File

Reading Input from Text File Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types

More information

Chapter. Let's explore some other fundamental programming concepts

Chapter. Let's explore some other fundamental programming concepts Data and Expressions 2 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Data and Expressions Let's explore some

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types

More information

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

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

Declaration and Memory

Declaration and Memory Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

More information

2: Basics of Java Programming

2: Basics of Java Programming 2: Basics of Java Programming CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

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

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

A+ Computer Science -

A+ Computer Science - import java.util.scanner; or just import java.util.*; reference variable Scanner keyboard = new Scanner(System.in); object instantiation Scanner frequently used methods Name nextint() nextdouble() nextfloat()

More information

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2 Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

Peer Instruction 1. Elementary Programming

Peer Instruction 1. Elementary Programming Peer Instruction 1 Elementary Programming 0 Which of the following variable declarations will not compile? Please select the single correct answer. A. int i = 778899; B. double x = 5.43212345; C. char

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

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

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 ELEMENTARY PROGRAMMING Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Chapter 2 Elementary Programming. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Chapter 2 Elementary Programming. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. Chapter 2 Elementary Programming 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems

More information

Computational Expression

Computational Expression Computational Expression ArrayList Iterators Janyl Jumadinova 7-14 November, 2018 Janyl Jumadinova Computational Expression 7-14 November, 2018 1 / 11 Collections Collection: an object that stores data;

More information

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 06 / 03 / 2015 Instructor: Michael Eckmann Today s Topics Finish up discussion of projected homeruns 162 as a constant (final) double vs. int in calculation Scanner

More information

Elementary Programming

Elementary Programming Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal

More information

Object Oriented Programming. Java-Lecture 1

Object Oriented Programming. Java-Lecture 1 Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen

More information

Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal

Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand variables Understand how to declare and use variables in Java Programs Learn how to formulate assignment statements

More information

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise

More information

CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 4: Java Basics (II) A java Program 1-2 Class in file.java class keyword braces {, } delimit a class body main Method // indicates a comment.

More information

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution Chapter 2: Elementary Programming CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations In the preceding chapter, you learned how to

More information

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

More information

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value. 3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

More information

A+ Computer Science -

A+ Computer Science - Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience import java.util.scanner; Try

More information

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII

AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU. Week 21/02/ /02/2007 Lecture Notes: ASCII AYBUKE BUYUKCAYLI KORAY OZUYAR MUSTAFA SOYLU Week 21/02/2007-23/02/2007 Lecture Notes: ASCII 7 bits = 128 characters 8 bits = 256characters Unicode = 16 bits Char Boolean boolean frag; flag = true; flag

More information

ESc101 : Fundamental of Computing

ESc101 : Fundamental of Computing ESc101 : Fundamental of Computing I Semester 2008-09 Lecture 9+10 Types Range of numeric types and literals (constants) in JAVA Expressions with values of mixed types 1 I : Range of numeric types and literals

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

More information

Input. Scanner keyboard = new Scanner(System.in); String name;

Input. Scanner keyboard = new Scanner(System.in); String name; Reading Resource Input Read chapter 4 (Variables and Constants) in the textbook A Guide to Programming in Java, pages 77 to 82. Key Concepts A stream is a data channel to or from the operating system.

More information

Chapter 3 Structured Program Development in C Part II

Chapter 3 Structured Program Development in C Part II Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called

More information

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Assignments Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4 Lecture 6 Complete for Lab 4, Project 1 Note: Slides 12 19 are summary slides for Chapter 2. They overview much of what we covered but are not complete.

More information

Eng. Mohammed S. Abdualal

Eng. Mohammed S. Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections

More information

Experiment No: Group B_4

Experiment No: Group B_4 Experiment No: Group B_4 R (2) N (5) Oral (3) Total (10) Dated Sign Problem Definition: Write a web application using Scala/ Python/ Java /HTML5 to check the plagiarism in the given text paragraph written/

More information

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4 Assignments Lecture 6 Complete for Project 1 Reading: 3.1, 3.2, 3.3, 3.4 Summary Program Parts Summary - Variables Class Header (class name matches the file name prefix) Class Body Because this is a program,

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

More information

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the

More information

ing execution. That way, new results can be computed each time the Class The Scanner

ing execution. That way, new results can be computed each time the Class The Scanner ing execution. That way, new results can be computed each time the run, depending on the data that is entered. The Scanner Class The Scanner class, which is part of the standard Java class provides convenient

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

Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6

Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6 Using Classes and Objects Chapters 3 Creating Objects Section 3.1 The String Class Section 3.2 The Scanner Class Section 2.6 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Creating

More information

Chapter 3 Structure of a C Program

Chapter 3 Structure of a C Program Chapter 3 Structure of a C Program Objectives To be able to list and describe the six expression categories To understand the rules of precedence and associativity in evaluating expressions To understand

More information

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents Variables in a programming language Basic Computation (Savitch, Chapter 2) TOPICS Variables and Data Types Expressions and Operators Integers and Real Numbers Characters and Strings Input and Output Variables

More information

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous CS256 Computer Science I Kevin Sahr, PhD Lecture 25: Miscellaneous 1 main Method Arguments recall the method header of the main method note the argument list public static void main (String [] args) we

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

CEN 414 Java Programming

CEN 414 Java Programming CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About Operators Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

More information

Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2 Primitive Data Types and Operations. Objectives Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,

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

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

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

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

Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual: Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

More information

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I Iterators ArrayList Janyl Jumadinova October 31, 2016 Iterators One of the most useful operations for any collection is the ability to run through each of the elements

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one

More information

Add Subtract Multiply Divide

Add Subtract Multiply Divide ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient

More information

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must

More information

Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)

Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a) Operators Representing and storing primitive data types is, of course, essential for any computer language. But, so, too, is the ability to perform operations on data. Java supports a comprehensive set

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

1.3b Type Conversion

1.3b Type Conversion 1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

Lecture Set 4: More About Methods and More About Operators

Lecture Set 4: More About Methods and More About Operators Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

More information

Basic Computation. Chapter 2

Basic Computation. Chapter 2 Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them

More information

Chapter 7. Additional Control Structures

Chapter 7. Additional Control Structures Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter

More information

Computer Science 145 Midterm 1 Fall 2016

Computer Science 145 Midterm 1 Fall 2016 Computer Science 145 Midterm 1 Fall 2016 Doodle here. This is a closed-book, no-calculator, no-electronic-devices, individual-effort exam. You may reference one page of handwritten notes. All answers should

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

Section 2: Introduction to Java. Historical note

Section 2: Introduction to Java. Historical note The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence

More information

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression Expressions and Statementst t Expression C Programming Lecture 6 : Operators Combination of constants,variables,operators, operators and function calls a+b 3.0*x 9.66553 tan(angle) Statement An expression

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

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

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education AP Computer Science Return values, Math, and double Distance between points Write a method that given x and y coordinates for two points prints the distance between them If you can t do all of it, pseudocode?

More information

Variables and Assignments CSC 121 Fall 2015 Howard Rosenthal

Variables and Assignments CSC 121 Fall 2015 Howard Rosenthal Variables and Assignments CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand variables Understand how to declare and use variables in Java Programs Learn how to formulate assignment statements

More information

Types and Expressions. Chapter 3

Types and Expressions. Chapter 3 Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

More information

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto Side Effects The 5 numeric operators don't modify their operands Consider this example: int sum = num1 + num2; num1 and num2 are unchanged after this The variable sum is changed This change is called a

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

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information