# Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters

Size: px
Start display at page:

Download "Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters"

Transcription

1 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 #4 Mathematical Functions & Characters

2 Mathematical Functions Java provides many useful methods in the Math class for performing common mathematical functions. A method is a group of statements that performs a specific task. We have already used methods like println() and nextint(). This lab introduces other useful methods in the Math class. They can be categorized as trigonometric methods, exponent methods, and service methods. Trigonometric Methods The Math class contains the following methods for performing trigonometric functions. Note that the parameters for sin, cos, and tan is an angle in radians. Exponent Methods Exponent methods in the Math class are shown below. 2

3 Rounding Methods The Math class contains five rounding methods as shown. Other mathematical functions min and max methods return the minimum and maximum numbers of two numbers. abs method returns the absolute value of the number. random method generates a random double value greater than or equal to 0.0 and less than 1.0. // Returns a random number between a and a + b, excluding a + b a + Math.random() * b For example, to generate a random number in the period [5,15]: (int)(5 + Math.random() * 11) Ex: Write a program that randomly generates a number of two digits, prompts the user to enter a two-digit number, and determines whether the user wins according to the following rules: 1. If the user input matches the lottery number in the exact order, the award is \$10, If all digits in the user input match all digits in the lottery number, the award is \$3, If one digit in the user input matches a digit in the lottery number, the award is \$1,000. 3

4 Scanner input = new Scanner(System.in); int lottery = (int) (Math.random() * 100); System.out.print("Enter your lottery pick (two digits): "); int guess = input.nextint(); int lotterydigit1 = lottery / 10; int lotterydigit2 = lottery % 10; int guessdigit1 = guess / 10; int guessdigit2 = guess % 10; System.out.println("The lottery number is " + lottery); if (guess == lottery) System.out.println("Exact match: you win \$10,000"); else if (guessdigit2 == lotterydigit1 && guessdigit1 == lotterydigit2) System.out.println("Match all digits: you win \$3,000"); else if (guessdigit1 == lotterydigit1 guessdigit1 == lotterydigit2 guessdigit2 == lotterydigit1 guessdigit2 == lotterydigit2) System.out.println("Match one digit: you win \$1,000"); else System.out.println("Sorry, no match"); Character Data Type and Operations The character data type, char, is used to represent a single character. A character literal is enclosed in single quotation marks. char letter = 'A'; char numchar = '4'; A string literal must be enclosed in double quotation marks (" "). A character literal is a single character enclosed in single quotation marks (' '). Therefore, "A" is a string, but 'A' is a character. 4

5 Encoding scheme Computers use binary numbers internally. A character is stored in a computer as a sequence of 0s and 1s. Mapping a character to its binary representation is called encoding. There are different ways to encode a character. How characters are encoded is defined by an encoding scheme. Most computers use ASCII, an 8-bit encoding scheme for representing all uppercase and lowercase letters, digits, punctuation marks, and control characters. Java supports Unicode, an encoding scheme established to support the interchange, processing, and display of written texts in the world s diverse languages. Unicode was designed as a 16-bit character encoding. The primitive data type char was intended to take advantage of this design by providing a simple data type that could hold any character. A 16-bit Unicode takes two bytes, preceded by \u, expressed in four hexadecimal digits that run from \u0000 to \uffff. Unicode includes ASCII code, with \u0000 to \u007f corresponding to the 128 ASCII characters. You can use ASCII characters such as 'X', '1', and '\$' in a Java program as well as Unicode. Thus, for example, the following statements are equivalent: char letter = 'A'; char letter = '\u0041'; // Character A's Unicode is 0041 Both statements assign character A to the char variable letter. The following table representing Unicode values for commonly used characters: The increment and decrement operators can also be used on char variables to get the next or preceding Unicode character. For example, the following statements display character C. 5

6 char ch = 'B'; System.out.println(++ch); Escape Sequences In Java, can we write a statement like the one below? System.out.println("He said "Java is fun""); No, we can't. This statement has syntax errors, as the second quotation terminates the string, and the compiler don t know what to do with the rest of the statement. Java uses a special notation to represent special characters. This special notation, called an escape sequence, consists of a backslash (\) followed by a character or a combination of digits. So now we can rewrite the previous statement using escape sequence. System.out.println("He said \"Java is fun\""); Note that the symbols \ and " together represent one character. Ex: Write ONE Java Statement to print to following lines to the Console: Welcome to "IUG\JavaLab" Lab4: Math Functions & Characters. 6

7 System.out.println("Welcome to \"IUG\\JavaLab\"\nLab4:\tMath Functions & Characters."); Casting between char and Numeric Types A char can be cast into any numeric type, and vice versa. char ch = (char)0x0041; // ch is character A When a floating-point value is cast into a char, the floating-point value is first cast into an int, which is then cast into a char. char ch = (char)65.25; // ch is character A When a char is cast into a numeric type, the character s Unicode is cast into the specified numeric type. int i = (int)'a'; // i is 65 Implicit casting can be used if the result of a casting fits into the target variable. Otherwise, explicit casting must be used. For example, since the Unicode of 'a' is 97, which is within the range of a byte, these implicit castings are fine: byte b = 'a'; int i = 'a'; But the following casting is incorrect, because the Unicode \ufff4 cannot fit into a byte: byte b = '\ufff4'; To force this assignment, use explicit casting, as follows: byte b = (byte) '\ufff4'; Ex: Write a program that prints the Unicode for '9' and '\$'. 7

8 char ninech = '9'; char dollarch = '\$'; System.out.println((int) ninech); // prints 57 System.out.println((int) dollarch); // prints 36 Note that all numeric operators can be applied to char operands. A char operand is automatically cast into a number if the other operand is a number or a character. If the other operand is a string, the character is concatenated with the string. For example, the following statements: int i = '2' + '3'; // (int)'2' is 50 and (int)'3' is 51 System.out.println("i is " + i); // i is 101 int j = 2 + 'a'; // (int)'a' is 97 System.out.println("j is " + j); // j is 99 System.out.println(j + " is the Unicode for character " + (char)j); // 99 is the Unicode for character c System.out.println("Lab " + '4'); Comparing and Testing Characters Two characters can be compared using the relational operators just like comparing two numbers. This is done by comparing the Unicode of the two characters. For example, /* true because the Unicode for 'a' (97) is less than the Unicode for 'b' (98). */ System.out.println('a' < 'b'); /* false because the Unicode for 'a' (97) is greater than the Unicode for 'A' (65). */ System.out.println('a' < 'A'); Ex: Write a program that reads a character and prints weather it's a capital letter, small letter or a digit. 8

9 char ch = 'A'; if (ch >= 'A' && ch <= 'Z') System.out.println(ch + " is an uppercase letter"); else if (ch >= 'a' && ch <= 'z') System.out.println(ch + " is a lowercase letter"); else if (ch >= '0' && ch <= '9') System.out.println(ch + " is a numeric character"); Java provides the following methods in the Character class for testing characters. Ex: Re-Write the previous exercise using the built-in Java methods. char ch = 'A'; if (Character.isUpperCase(ch)) System.out.println(ch + " is an uppercase letter"); else if (Character.isLowerCase(ch)) System.out.println(ch + " is a lowercase letter"); else if (Character.isDigit(ch)) System.out.println(ch + " is a numeric character"); Lab Work Ex1: A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree. The formula for computing the area of a regular polygon is n s 2 Area = 4 tan ( π n ) 9

10 s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Scanner input = new Scanner(System.in); System.out.print("Enter the number of sides: "); int numberofsides = input.nextint(); System.out.print("Enter the side: "); double side = input.nextdouble(); double area = numberofsides * Math.pow(side, 2) / (Math.tan(Math.PI / numberofsides) * 4); System.out.println("The area of the polygon is " + area); Ex2: Write a program that prompts the user to enter a character ch. If the character is 'U' or 'u' then generate a random uppercase letter. If the character is 'L' or 'l' then generate a random lowercase letter. Else, print the character. Scanner input = new Scanner(System.in); System.out.print("Enter a character: "); char c = input.next().charat(0); char random; if (c == 'U' c == 'u') { random = (char) ('A' + Math.random() * ('Z' - 'A' + 1)); System.out.println("Randomly generated uppercase letter is: \"" + random + "\""); } else if (c == 'L' c == 'l') { random = (char) ('a' + Math.random() * ('z' - 'a' + 1)); System.out.println("Randomly generated lowercase letter is: \"" + random + "\""); } else { System.out.println("Your character\\ \"" + c + "\""); } 10

11 Ex3: Write a program that receives an ASCII code (an integer between 0 and 127) and displays its character. Scanner input = new Scanner(System.in); System.out.print("Enter an ASCII code: "); int code = input.nextint(); System.out.println("The character for ASCII code " + code + " is " + (char)code); Homework 1. Write a program that reads three numbers and prints the maximum number. (Use Math class). 2. Write statements that assign random integers to the variable n in the following ranges: a) 1 n 2. b) 1 n 100. c) 0 n 9. d) 1000 n e) 1 n 1. f) 3 n Write a program that prints the following characters to the console \ and "? 4. Write a program that prompts the user to enter a single character. Print whether the character Vowel or Consonant, depending on the user input. 5. Write a program that receives a character and displays its Unicode. Good Luck 11

### CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

### 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

### Module 4: Characters, Strings, and Mathematical Functions

Module 4: Characters, Strings, and Mathematical Functions Objectives To solve mathematics problems by using the methods in the Math class ( 4.2). To represent characters using the char type ( 4.3). To

### Computer Programming, I. Laboratory Manual. Experiment #6. Loops

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 #6

### Chapter 4 Mathematical Functions, Characters, and Strings

Chapter 4 Mathematical Functions, Characters, and Strings Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations Suppose you need to estimate

### Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

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 #2

### 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

### 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

### Computer Programming, I. Laboratory Manual. Experiment #7. Methods

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 #7

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Mathematical Functions Java provides many useful methods in the Math class for performing common mathematical

### Chapter 4. Mathematical Functions, Characters, and Strings. Program Listings

Chapter 4 Mathematical Functions, Characters, and Strings Program Listings Contents Listing 4.1 Compute Angles... 3 Listing 4.2 Order Two Cities... 5 Listing 4.3 Guess Birthday... 6 Listing 4.4 Hex Digit

### Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius

### Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

### Eng. Mohammed Abdualal

Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 4 Characters

### Computer Programming, I. Laboratory Manual. Experiment #5. Strings & Text Files Input

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 #5

### 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

### 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,

### Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection

### 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

### Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

### 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

### 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

### Zheng-Liang Lu Java Programming 45 / 79

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

### Elementary Programming. CSE 114, Computer Science 1 Stony Brook University

Elementary Programming CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Variables In a program, the variables store data Primitive type variables store single pieces

### 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

### CHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS

CHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) MATHEMATICAL FUNCTIONS Java

### JAVA Programming Concepts

JAVA Programming Concepts M. G. Abbas Malik Assistant Professor Faculty of Computing and Information Technology University of Jeddah, Jeddah, KSA mgmalik@uj.edu.sa Programming is the art of Problem Solving

### 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

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

### Motivations 9/14/2010. Introducing Programming with an Example. Chapter 2 Elementary Programming. Objectives

Chapter 2 Elementary Programming 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

### Chapter 2 Elementary Programming

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

### 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

### Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

### 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

### Important Java terminology

1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as

### CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II)

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs How to generate

### 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

### 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

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### 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

### Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

### 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

### char ch = astring; //where astring is a String..illegal char ch = A ; //illegal

13-1 Character type and types can t be stored into each other. The following lines of code are : char ch = astring; //where astring is a String..illegal char ch = A ; //illegal String x = xchar; //where

### Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 LNGG 1003 Khaleel I. Shaheen Introduction to Computers Laboratory Manual Experiment

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

### Computer Programming, I. Laboratory Manual. Final Exam Solution

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 Final Exam Solution

### 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

### 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;

### Getting started with Java

Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

### Chapter 3. Selections. Program Listings

Chapter 3 Selections Program Listings Contents Listing 3.1 Addition Quiz... 3 Listing 3.2 Simple If Demo... 4 Listing 3.3 Subtraction Quiz... 5 Listing 3.4 Compute And Interpret BMI... 6 Listing 3.5 Compute

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### Chapter 4 Mathematical Functions, Characters, and Strings

Chapter 4 Mathematical Functions, Characters, and Strings 4.1 Introduction The focus of this chapter is to introduce mathematical functions, characters, string objects, and use them to develop programs.

### 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

### Chapter 3 Selections. 3.1 Introduction. 3.2 boolean Data Type

3.1 Introduction Chapter 3 Selections Java provides selections that let you choose actions with two or more alternative courses. Selection statements use conditions. Conditions are Boolean expressions.

### Date: Dr. Essam Halim

Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use

### 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

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

### Using Java Classes Fall 2018 Margaret Reid-Miller

Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class

### Basic data types. Building blocks of computation

Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

### MATHEMATICAL FUNCTIONS CHARACTERS, AND STRINGS. INTRODUCTION IB DP Computer science Standard Level ICS3U

C A N A D I A N I N T E R N A T I O N A L S C H O O L O F H O N G K O N G MATHEMATICAL FUNCTIONS CHARACTERS, AND STRINGS P1 LESSON 4 P1 LESSON 4.1 INTRODUCTION P1 LESSON 4.2 COMMON MATH FUNCTIONS Java

### JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly

### 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

### 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

### 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

### 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

### 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

### Object-Oriented Programming

Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

### Chapter 02: Using Data

True / False 1. A variable can hold more than one value at a time. ANSWER: False REFERENCES: 54 2. The int data type is the most commonly used integer type. ANSWER: True REFERENCES: 64 3. Multiplication,

### 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

### 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,

### Review for Test 1 (Chapter 1-5)

Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits.

Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

### 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

### What did we talk about last time? Examples switch statements

Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

### boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

CSCI 150 Fall 2007 Java Syntax The following notes are meant to be a quick cheat sheet for Java. It is not meant to be a means on its own to learn Java or this course. For that you should look at your

### Chapter 2: Using Data

Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

### Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and

### 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

### 12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

### Java Classes: Math, Integer A C S L E C T U R E 8

Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

### 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,

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

### Computer Programming, I. Laboratory Manual. Experiment #9. Multi-Dimensional Arrays

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 #9

### Java Programming Fundamentals. Visit for more.

Chapter 4: Java Programming Fundamentals Informatics Practices Class XI (CBSE Board) Revised as per CBSE Curriculum 2015 Visit www.ip4you.blogspot.com for more. Authored By:- Rajesh Kumar Mishra, PGT (Comp.Sc.)

www.thestudycampus.com Methods Let s imagine an automobile factory. When an automobile is manufactured, it is not made from basic raw materials; it is put together from previously manufactured parts. Some

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### 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

### Basic Operations jgrasp debugger Writing Programs & Checkstyle

Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent

### Section 2.2 Your First Program in Java: Printing a Line of Text

Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

### 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/

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

### 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

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### 1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius