Characters. Character Data char data type – Represents one character – char literals indicated with ' '

Slides:



Advertisements
Similar presentations
This is Java Jeopardy.
Advertisements

C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Chapter 1 Chapter 2 Chapter 3 Code Gone Wrong Random 5 pt 5 pt 5 pt
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
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.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Introduction to Computers and Programming Lecture 7:
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
1 Character Processing How characters can be treated as small integers? How characters are stored and manipulated in a machine? How use is made of certain.
String Escape Sequences
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Introduction to Python
Input & Output: Console
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
February 14, 2005 Characters, Strings and the String Class.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Character Set It is set of Characters/digits/symbol which is valid in C++. Example – A-Z, (white space) C++ Character Set It is set of.
Primitive Variables.
Agenda ASCII char N int Character class char N String Bitwise operators homework.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Lab 4 - Variables. Information Hiding General Principle: – Restrict the access to variables and methods as much as possible Can label instance variables.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
CSC Programming for Science Lecture 8: Character Functions.
Cryptography.
1 MATERI PENDUKUNG TIPE DATA Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Characters and Strings
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.
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.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 2 Basic Computation
Java Variables and Types
Character Processing How characters can be treated as small integers?
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CSE 303 Lecture 14 Strings in C
COMP3221: Microprocessors and Embedded Systems
getline() function with companion ignore()
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
2.1 Parts of a C++ Program.
An overview of Java, Data types and variables
Introduction to Java, and DrJava part 1
Chapter 2: Introduction to C++.
Character Processing How characters can be treated as small integers?
functions: argument, return value
The Data Element.
The Data Element.
C Characters and Strings
getline() function with companion ignore()
Presentation transcript:

Characters

Character Data char data type – Represents one character – char literals indicated with ' '

Char vs String Char – One character – literals use ' ' String – 0+ characters – literals use " "

Character Data char is integer data type – 1 byte of space : 256 values – Assumed to represent characters

Chars as Integers Integers understood as ASCII codes – Can store integers as chars

Chars And Math Doing math – char converted to an int:

Chars And Math Adding/subtracting and cast back to character shifts char:

Letter Number Identify letter of alphabet: 'f' – 'a' –

Random Char Generate random char: – Make number 0-25 – Add to 'a'

Comparisons Chars compare like other numbers:

But Capitals different than lower case: – lower case is "greater"

Why is this broken? This prints nothing:

Why is this broken? This prints nothing: '3' is char 51 on ASCII chart if( 51 == 3 )

Fixed This works:

Special Chars Some characters hard to represent – return, tab, ' Escape sequences used to represent them – \ means next char is special: '\t' : tab char '\'' : ' char

Escape Codes Common codes:

Escape Codes Used in strings and as chars:

Case Conversion Convert lower to upper: – Subtract 'a' to find letter number – Add that amount to 'A'

Char Functions library has char related functions: – – all return int is… interpret as boolean to… interpret as char

Conversion 2 More readable conversion:

Conversion 3 toupper / tolower do their own sanity checks