Converting Between Numbers and Characters CSC 1401: Introduction to Programming with Java Week 4 – Lecture 3 Wanda M. Kunkle.

Slides:



Advertisements
Similar presentations
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer Dr. Sadaf Tanveer,
Advertisements

CSC Programming for Science Lecture 5: Actual Programming.
Methods in Java CSC 1401: Introduction to Programming with Java Week 7 – Lecture 2 Wanda M. Kunkle.
Introduction to Computers and Programming Lecture 7:
Boolean Types & Compound Conditionals CSC 1401: Introduction to Programming with Java Lecture 4 – Part 3 Wanda M. Kunkle.
Reverse Polish Notation (RPN) & Stacks CSC 1401: Introduction to Programming with Java Week 14 – Lecture 2 Wanda M. Kunkle.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
ECS15 for and sequence. Comments  Another way to repeat.
Repetition Structures: Nested Loops CSC 1401: Introduction to Programming with Java Week 6 – Lecture 2 Wanda M. Kunkle.
More on Arrays CSC 1401: Introduction to Programming with Java Week 10 – Lectures 2 & 3 Wanda M. Kunkle.
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
Is ASCII the only way? For computers to do anything (besides sit on a desk and collect dust) they need two things: 1. PROGRAMS 2. DATA A program is a.
1 More About Methods in Java CSC 1401: Introduction to Programming with Java Week 7 – Lecture 3 Wanda M. Kunkle.
Java Applets CSC 1401: Introduction to Programming with Java Week 13 – Lecture 1 Wanda M. Kunkle.
FUNDAMENTAL DATA TYPES CSC 171 LECTURE 4. How do Computers represent information? Computers are switches Switches are “on” or “off” Suppose we want to.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 – Part 2 Wanda M. Kunkle.
Multidimensional Arrays Histograms CSC 1401: Introduction to Programming with Java Week 11 – Lecture 1 Wanda M. Kunkle.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Repetition Structures: Do-while Loop Random Number Generation CSC 1401: Introduction to Programming with Java Week 6 Wanda M. Kunkle.
Implementing Stacks Using Arrays CSC 1401: Introduction to Programming with Java Week 14 – Lecture 1 Wanda M. Kunkle.
Data Input and Output Using the Library Software CSC 1401: Introduction to Programming with Java Lecture 4 – Part 1 Wanda M. Kunkle.
Selection Structures: Switch CSC 1401: Introduction to Programming with Java Week 4 – Lecture 1 Wanda M. Kunkle.
Parameters, Arguments, Local Variables, and Scope CSC 1401: Introduction to Programming with Java Week 8 – Lecture 1 Wanda M. Kunkle.
File Input and Output CSC 1401: Introduction to Programming with Java Week 4 – Lecture 2 Wanda M. Kunkle.
The Java String Type CSC 1401: Introduction to Programming with Java Week 7 – Lecture 1 Wanda M. Kunkle.
Introduction to Arrays CSC 1401: Introduction to Programming with Java Week 10 – Lecture 1 Wanda M. Kunkle.
More on Recursion Averting Program Crashes CSC 1401: Introduction to Programming with Java Week 9 – Lecture 3 Wanda M. Kunkle.
Introduction to Computing Using Python Chapter 6  Encoding of String Characters  Randomness and Random Sampling.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
1 herbert van de sompel CS 502 Computing Methods for Digital Libraries Cornell University – Computer Science Herbert Van de Sompel
Unit 3: Java Data Types Math class and String class.
Chapter 7—Objects and Memory The Art and Science of An Introduction to Computer Science ERIC S. ROBERTS Java Objects and Memory C H A P T E R 7 Yea, from.
Fractions + & – Mixed Numbers Can you simplify the following with ease? 1 5 / / 4 or 2 7 / / 3 If not then run through this slide show,
SE-1021 Software Engineering II Week 8, Class 1 Return Exam Producing UML diagrams automatically in EA Poll Everywhere Files Tomorrow Week 6 HW due (if.
April 14, 2015Applied Discrete Mathematics Week 10: Equivalence Relations 1 Properties of Relations Definition: A relation R on a set A is called transitive.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
1 Principles of Information Technology Introduction to Software and Information Systems Copyright © Texas Education Agency, All rights reserved.
Unit 2 Test: Tues 11/3. ASCII / Unicode –Each letter, symbol, etc has a # value –See ascii table (in folder) –To convert a char into its ascii value,
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.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
CSC 205 Java Programming II Introduction. Topics Syllabus Course goals and approach Review I Java language fundamentals.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
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.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
Print the sample banner slides or customize with your own message. Click on the letter and type your own text. Use one character per slide. C.
Calculus, Section 1.4.
Algebra.
Variables Mr. Crone.
SE-1021 Software Engineering II
Principles of Information Technology
FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.
Type Conversion, Constants, and the String Object
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
Access Database for CIS17
Chapter 2.
Binary, Octal and Hex Numbers Copyright Thaddeus Konar
Unit-2 Objects and Classes
COMS 161 Introduction to Computing
Access Database for CIT12
Other types of variables
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Presentation transcript:

Converting Between Numbers and Characters CSC 1401: Introduction to Programming with Java Week 4 – Lecture 3 Wanda M. Kunkle

2 The Character (char) Type The character ( char ) type in Java is considered a numeric type because it is stored internally as a number (technically, a non-negative integer). The character ( char ) type in Java is considered a numeric type because it is stored internally as a number (technically, a non-negative integer). Do you remember our earlier discussion about ASCII/Unicode values for letters and digits? Do you remember our earlier discussion about ASCII/Unicode values for letters and digits? If not, I have again provided the table of characters and their numeric values on the next slide (A similar table appears on p. 100 in your book.). If not, I have again provided the table of characters and their numeric values on the next slide (A similar table appears on p. 100 in your book.).

3 ASCII/Unicode Values for Letter and Digit Characters Character ASCII/Unicode Value '0' through '9' 48 through 57 'A' through 'Z' 65 through 90 'a' through 'z' 97 through 122

4 Converting Between Characters and Numbers Since the character ( char ) type is stored internally as a number, it is easy to convert between characters and numbers in Java. Since the character ( char ) type is stored internally as a number, it is easy to convert between characters and numbers in Java. For the same reason, it is possible to perform mathematical operations on characters in Java (“ditto,” for the C and C++ programming languages). For the same reason, it is possible to perform mathematical operations on characters in Java (“ditto,” for the C and C++ programming languages).

5 Converting Between Characters and Numbers Number to character Number to character –(char)(48) = 0... Why? Character to number Character to number –(int)('x') = Why? Character math Character math –'a' - 'A' = Why? Combining both Combining both –(char)('E' + ' ') = e... Why?

6 Sample Programs Now let’s look at some sample programs that demonstrate mathematical/conversion operations on characters: Now let’s look at some sample programs that demonstrate mathematical/conversion operations on characters: –MathOpsOnChars.java MathOpsOnChars.java –CopyTextFile2.java CopyTextFile2.java

7 Sample Programs Now let’s look at a demo program relevant to our current Mastermind assignment: Now let’s look at a demo program relevant to our current Mastermind assignment: –HeadsOrTails.java HeadsOrTails.java