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

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

Chapter 4 Mathematical Functions, Characters, and Strings

Eng. Mohammed Abdualal

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

CHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS

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

Chapter 4. Mathematical Functions, Characters, and Strings

Chapter 12 Strings and Characters. Dr. Hikmat Jaber

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

Chapter 4 Mathematical Functions, Characters, and Strings

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

Chapter 2 Elementary Programming

Chapter 2 ELEMENTARY PROGRAMMING

CS-201 Introduction to Programming with Java

Strings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

String is one of mostly used Object in Java. And this is the reason why String has unique handling in Java(String Pool). The String class represents

Chapter 3 Mathematical Functions, Strings, and Objects

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Chapter 2 Primitive Data Types and Operations. Objectives

More on variables and methods

Java Strings. Interned Strings. Strings Are Immutable. Variable declaration as String Object. Slide Set 9: Java Strings and Files

Module 4: Characters, Strings, and Mathematical Functions

Chapter 2 Primitive Data Types and Operations

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

Chapter 8 Strings. Chapter 8 Strings

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

Java Basic Datatypees


Class Library java.lang Package. Bok, Jong Soon

Chapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9

Basic data types. Building blocks of computation

"Hello" " This " + "is String " + "concatenation"

Chapter 2 Primitive Data Types and Operations

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

Programming with Java

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

Visual C# Instructor s Manual Table of Contents

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

Full file at

Strings. Strings and their methods. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

We now start exploring some key elements of the Java programming language and ways of performing I/O

Getting started with Java

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

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

Chapter 2: Using Data

JAVA Programming Concepts

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

Chapter 2 Elementary Programming

ANSI C Programming Simple Programs

TCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.

Eng. Mohammed Abdualal

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

Chapter 6 Primitive types

Chapter 2: Using Data

Chapter 2. Outline. Simple C++ Programs

CS112 Lecture: Primitive Types, Operators, Strings

Operations. Making Things Happen

Types and Expressions. Chapter 3

Strings, Strings and characters, String class methods. JAVA Standard Edition

CST242 Strings and Characters Page 1

Introductory Mobile Application Development

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Variables, Constants, and Data Types

Using Java Classes Fall 2018 Margaret Reid-Miller

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

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

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Strings, characters and character literals

Engineering Problem Solving with C++, Etter/Ingber

Creating Strings. String Length

APPENDIX A: SUMMARY OF IMPORTANT JAVA FEATURES

Chapter 10: Creating and Modifying Text Lists Modules

Chapter 2: Data and Expressions

What is a Computer? Chapter 1-9, 12-13, 18, 20, 23 Review Slides

Chapter 1-9, 12-13, 18, 20, 23 Review Slides. What is a Computer?

Basics of Java Programming

USING LIBRARY CLASSES

Chapter 2 Working with Data Types and Operators

6 Character Classification and Utilities Module (chars.hhf)

Lab #7 Library Classes and JUnit Testing. Daniel Amyot, Diana Inkpen, Alan. Agenda. In this lab, you are going to create your own

Full file at

Mathematical Functions, Characters, and Strings. APSC 160 Chapter 4

Formatted Output Pearson Education, Inc. All rights reserved.

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

STUDENT LESSON A10 The String Class

Primitive Data Types: Intro

4 Programming Fundamentals. Introduction to Programming 1 1

Quick MATLAB Syntax Guide

Fall 2017 CISC124 9/27/2017

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

Princeton University. Computer Science 217: Introduction to Programming Systems. Data Types in C

CS 1301 Ch 8, Part A

VARIABLES AND TYPES CITS1001

Review for Test 1 (Chapter 1-5)

B.V. Patel Institute of BMC & IT, UTU 2014

Lecture Set 2: Starting Java

Transcription:

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 provides many useful methods in the Math class for performing common mathematical functions Math constants Math.PI Math.E 1

P1 LESSON 4.2 COMMON MATH FUNCTIONS Math Class common math functions Trigonometry Exponential Miscellaneous sin(radians) exp(x) ceil(x) cos(radians) log(x) floor(x) tan(radians) log10(x) rint(x) toradian (degrees) power(a,b) round(x) todegree (radians) sqrt(x) max(a,b) asin(a) min(a,b) acos(a) abs(x) atan(a) a character data type represents a single character a string literal must be enclosed in quotation marks a character literal is a single character enclosed in single quotation marks refer to the Computer Science blog for the ASCII Character Table Special Characters escape sequence for special characters Escape Sequence Name Unicode \b backspace \u0008 \t tab \u0009 \n linefeed \u000a \f formfeed \u000c \r carriage return \u000d \\ backslash \u005c \ double quotation \u0022 2

a char can be cast into any numeric type, and vice versa Code Result char ch = (char)0xab0041; ch is character A int i = (int)'a'; iis integer 65 byte b = (byte)'\ufff4; b is byte 0 Methods common methods Method isdigit(ch) isletter(ch) isletterordigit(ch) islowercase(ch) isuppercase(ch) tolowercase(ch) touppercase(ch) Description returns true if ch is a digit returns true if ch is a letter returns true if ch is a digit or a letter returns true if ch is a lowercase letter returns true if ch is a uppercase letter returns the lowercase of ch returns the uppercase of ch a string is a sequence of characters the String type is not a primitive type the String type is a reference type 3

Methods common methods Method length() charat(index) concat(s1) touppercase() tolowercase() trim() Description returns the number of characters in the string returns the character at the specified index of the string concatenates the string with s1 returns a new string with all letters in uppercase returns a new string with all letters in uppercase returns a new string with whitespace characters trimmed on both sides Methods common methods Comparison equals(s1) equalsignorecase() compareto(s1) comparetoignorecase(s1) startswith(prefix) endswith(suffix) contains(s1) Subtring substring(beginindex) substring(beginindex, endindex) index(ch) indexof(s) lastindexof(ch) lastindexof(s) Conversion convert a numeric string to integer int intvalue = Integer.parseInt(intString); convert a numeric string to double double doublevalue = Double.parseDouble(doubleString); convert a number into string String s = number + ; 4

Practice write a program that reads two inputs from the console for your first name and last name concatenates the two inputs with a space in between based on the concatenated string, displays the total number of characters the character at index 1 the string in UPPERCASE P1 LESSON 4.5 CASE STUDY P1 LESSON 4.6 FORMATTING CONSOLE OUTPUT use the System.out.printf method to display formatted output on the console Format Specifier Output %b a Boolean value %c a character %d a decimal integer %f a floating-point number %e a number in scientific notation %s a string 5

P1 LESSON 4 MATH FUNCTIONS Homework Pg. 153 #4.11, 4.12, 4.15, 4.21 6