1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Java Planning our Programs Flowcharts Arithmetic Operators.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Hand Crafting your own program By Eric Davis for CS103.
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
Mathematical Operators: working with floating point numbers and more operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
1 Fundamental Data Types. 2 Outline  Primitive Data Types  Variable declaration  Numbers and Constants  Arithmetic Operators  Arithmetic Operator.
Lecture 4 Types & Expressions COMP1681 / SE15 Introduction to Programming.
Numerical Data Recitation – 01/30/2009
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Intro to CS – Honors I Programming Basics GEORGIOS PORTOKALIDIS
Introduction to Information and Computer Science Computer Programming Lecture c This material (Comp4_Unit5c), was developed by Oregon Health and Science.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
VARIABLES Introduction to Computer Science 1- COMP 1005, 1405 Instructor : Behnam Hajian
Java Methods. Topics  Declaring fields vs. local variables  Primitive data types  Strings  Compound Assignment  Conversions from one value to another.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 2 Elementary Programming
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CPS120: Introduction to Computer Science Operations Lecture 9.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Elementary Programming.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Java Programming Language Lecture27- An Introduction.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CompSci 230 S Programming Techniques
Topic 2 Elementary Programming
Elementary Programming
Chapter 2 Elementary Programming
Multiple variables can be created in one declaration
Data types, Expressions and assignment, Input from User
OPERATORS (1) CSC 111.
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2: Java Fundamentals
CS150 Introduction to Computer Science 1
elementary programming
CS2011 Introduction to Programming I Elementary Programming
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Unit 3: Variables in Java
Chapter 2: Java Fundamentals cont’d
Chapter 2 Lecture 2-3: Loop Figures and Constants reading:
Presentation transcript:

1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators

Assignment 3>> Review from Last Week

Naming constants as FINAL>>3 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Assignment 3 Review on website

Example>> Defining Named Constants public —no restrictions on where this name can be used static —must be included, but explanation has to wait final —the program is not allowed to change the value The remainder of the definition is similar to a variable declaration and gives the type, name, and initial value. A declaration like this is usually at the beginning of the file and is not inside the main method definition. public static final double PI = ;

Mini exercise>> FINAL MODIFIER EXAMPLE public class Average3 { public static final int DIVISOR = 3; public static void main(String[] args) { …….. average = average/DIVISOR; ………. }

Coding>> FIRST THINGS FIRST 1.Create folder TonightsWork 2.Include SavitchIn.class 3.Start with empty “main” class

Tonight's lecture>>7 Try to change RATE and observe error messages public class Junk { public static final double RATE = 2.765; public static void main(String[] args) { RATE = 4.768; System.out.println(RATE); }

Class lab type casting>>8 CSC 110AA Lecture: Type Casting

Code>>9 Class Lab Type Casting  Create several variables in a program with different types (i.e. int and double)  Perform several mathematical calculations on the numbers (i.e. multiplication, division) and output the results  Type cast results and output the numbers  Observe error messages  Note loss of precision  What happens with different casts on same expression?

10 public class TypeCast { public static void main(String[] args) { int x = 4; int y = 7; int z = 22; double a = 14.27; double b = 8.88; double c = ; int intAnswer; double doubleAnswer; intAnswer = (int)(a/c); System.out.println(intAnswer); doubleAnswer = x/c; System.out.println(doubleAnswer); } }//Type cast a character>>

END11 public class TypeCastCharacter { public static void main(String[] args) { char letter = ‘z’; int letterValue; letterValue = (int)letter System.out.println(“The letter is “ + letter); System.out.println(“The integer value is “ + letterValue); } Class Lab Type Casting Characters