Eng. Mohammed Abdualal
|
|
- Helena Strickland
- 6 years ago
- Views:
Transcription
1 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 & Strings Eng. Mohammed Abdualal October 10, 2015
2 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. Example: char letter = 'A'; char numchar = '5'; In Java, char values represent Unicode characters. Unicode is a 16-bit character encoding that supports the world's major languages. You can indicate a Unicode character using \uxxxx escape sequence. Each X in the escape sequence is a hexadecimal digit. As example, character A can be represented in other way using Unicode encoding: char letter = '\u0041'; // Character A's Unicode is 0041 The following table representing Unicode values for commonly used characters: Characters Code Value in Decimal Unicode Value '0' to '9' 48 to 57 \u0030 to \u0039 'A' to 'Z' 65 to 90 \u0041 to \u005a 'a' to 'z' 97 to 122 \u0061 to \u007a Escape Sequences for Special Characters Java uses an escape sequence to represent special characters, which consists of a backslash (\) followed by a character or a combination of digits. For example, \t is an escape sequence for Tab character. The symbols in an escape sequence are interpreted as a whole rather than individually. An escape sequence is considered as a single character. 2
3 The following table lists escape sequences for special characters in java: Escape Sequence Name Unicode Code \b Backspace \u0008 \t Tab \u0009 \n Linefeed \u000a \f Formfeed \u000c \r Carriage Return \u000d \\ Backslash \u005c \ Double Quote \u0022 \ Single Quote \u0027 Task 1 Write ONE Java Statement to print to following lines to the Console: Welcom to "Java" Lab#4: Strings & Loops Casting between char and Numeric Types A char can be cast into a numeric type, for example, int or byte. When a char is cast into a numeric type, the character s Unicode is cast into the specified numeric type. Example: int i = (int) 'A'; // The Unicode of character A is assigned to i System.out.println(i); // i is 65 Implicit casting can be used if the result of a casting fits into the target variable. For example, since the Unicode of 'A' is 65, which is within the range of int, these implicit castings are fine: int i = 'A'; // i is 65 char c = 65; // c is 'A' 3
4 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("Chapter " + '2'); display i is 101 j is is the Unicode for character c Chapter 2 Task 2 Try to discover the Unicode code for numbers chars: 0, 1, 2,, 9. Comparting and Testing Characters You can use the same numeric comparison operators for comparing characters. Hence, 'a' < 'b' is true because the Unicode for 'a' (97) is less than the Unicode for 'b' (98). However, Java provides some static methods in Character class for comparing and converting characters. The following table lists some of those useful methods: Method isdigit(ch) isletter(ch) isletterordigit(ch) islowercase(ch) Description Returns true if the specified character is a digit. Returns true if the specified character is a letter. Returns true if the specified character is a letter or digit Returns true if the specified character is a lowercase letter. 4
5 isuppercase(ch) tolowercase(ch) touppercase(ch) Returns true if the specified character is an uppercase letter. Returns the lowercase of the specified character. Returns the uppercase of the specified character. Example: Write a program that receives a character, and check if it is a digit or letter. If digit, print its Unicode code. If letter, print its toggle case. Else, print not a digit nor a letter. FindTheUnicodeOfACharacter.java String s = JOptionPane.showInputDialog("Enter a character"); // Get the first character of a line char c = s.charat(0); if (Character.isDigit(c)) { // Character implicitly converted into int System.out.println(c + 0); } else if (Character.isUpperCase(c)) { System.out.println(Character.toLowerCase(c)); } else if (Character.isLowerCase(c)) { System.out.println(Character.toUpperCase(c)); } else { System.out.println("Not a digit nor a letter"); } 5
6 The String Type A string is a sequence of characters. To represent a string of characters, use the data type called String. A sequence of characters are enclosed in double quotation marks. Example: String str = "Hello World"; String is a predefined class in the Java library. It contains many useful methods manipulating characters. The following table lists the String methods for obtaining string length, for accessing characters in the string, for converting a string to upper or lowercases, and for trimming a string. Method Description length() Returns the number of characters in this string. charat(index) Returns the character at the specified index from this string. touppercase() Returns a new string with all letters in uppercase. tolowercase() Returns a new string with all letters in lowercase. trim() Returns a new string with whitespace characters trimmed on both sides. Getting Characters from a String The str.charat(index) method can be used to retrieve a specific character in a string str, where the index is between 0 and str.length() 1. For example, message.charat(0) returns the character W, as shown in the next figure. Note that the index for the first character in the string is 0. 6
7 Caution Attempting to access characters in a string str out of bounds is a common programming error. To avoid it, make sure that you do not use an index beyond str.length() 1. Example: Write a Java program to prompt the user to enter a line and output the following: How many characters in the line? The fifth character (if exists) All characters in uppercase All characters in lowercase Manipulating String String str = JOptionPane.showInputDialog("Enter a line"); // Remove white spaces from both sides str = str.trim(); // Count characters int length = str.length(); System.out.println("Length is: " + length); // Get the fifth character if (length >= 5) System.out.println("Fifth character is: " + str.charat(4)); else System.out.println("The fifth character does not exist"); System.out.println("Uppercase: " + str.touppercase()); System.out.println("Lowercase: " + str.tolowercase()); Comparing Strings Method Description equals(s1) Returns true if this string is equal to string s1. equalsignorecase(s1) Returns true if this string is equal to string s1; it is case insensitive. compareto(s1) Returns an integer greater than 0, equal to 0, or less than 0 to indicate whether this string is greater than, equal to, or less than s1. comparetoignorecase(s1) Same as compareto except that the comparison is case insensitive. startswith(prefix) Returns true if this string starts with the specified prefix. endswith(suffix) Returns true if this string ends with the specified suffix. contains(s1) Returns true if s1 is a substring in this string. 7
8 Obtaining Substrings You can obtain a substring from a string using the substring method. For example: String message = "Welcome to Java"; String message = message.sustring(0, 11)+"HTML"; The string message now becomes "Welcome to HTML". Note that the last character (11) is excluded. Finding a Character or a Substring in a String The String class provides several versions of indexof and lastindexof methods to find a character or a substring in a string, as shown in the following table: Method indexof(ch) indexof(ch, fromindex) indexof(s) indexof(s, fromindex) lastindexof(ch) lastindexof(ch, fromindex) Description Returns the index of the first occurrence of ch in the string. Returns the index of the first occurrence of ch after fromindex in the string. Returns the index of the first occurrence of string s in this string. Returns the index of the first occurrence of string s in this string after fromindex. Returns the index of the last occurrence of ch in the string. Returns the index of the last occurrence of ch before fromindex in this string. 8
9 lastindexof(s) Returns the index of the last occurrence of string s. lastindexof(s, fromindex) Returns the index of the last occurrence of string s before fromindex. Note that all the previous methods return (-1) if not matched. Examples: 11 "Welcome to Java".indexOf('W') returns 0 "Welcome to Java".indexOf('o') returns 4 "Welcome to Java".indexOf('o', 5) returns 9 "Welcome to Java".indexOf("come") returns 3 "Welcome to Java".indexOf("Java", 5) returns 11 "Welcome to Java".indexOf("java", 5) returns -1 "Welcome to Java".lastIndexOf('W') returns 0 "Welcome to Java".lastIndexOf('o') returns 9 "Welcome to Java".lastIndexOf('o', 5) returns 4 "Welcome to Java".lastIndexOf("come") returns 3 "Welcome to Java".lastIndexOf("Java") returns Example: Write a Java program to prompt the user to enter his full name as FirstName LastName, and the program prints each word in a line. Solution String s = JOptionPane.showInputDialog("Enter Full Name"); int sp = s.indexof(" "); String firstname = s.substring(0, sp); String lastname = s.substring(sp + 1); System.out.println("First Name is: " + firstname); System.out.println("Last Name is: " + lastname); Note that there is a better solution for the previous example, using StringTokenizer class, which can be used as follow: Solution using StringTokenizer String s = JOptionPane.showInputDialog("Enter Full Name"); StringTokenizer st = new StringTokenizer(s, " "); String token; while (st.hasmoretokens()) { token = st.nexttoken(); System.out.println(token); } 9
10 10
11 Exercises: Part 1: Write a program that prompts the user to enter a character c and check which character is entered: If 'U', then generate a random uppercase letter. If 'L', then generate a random lowercase letter. Your program should ignore the case of the character (uppercase = lowercase). Else, print: (Your character\ "o"). replace o with the input character. Sample Input U L X Sample Output Randomly generated uppercase letter is: "M" Randomly generated uppercase letter is: "g" Your character\ "x" Hint: to generate a random number r in range a <= r <= b, use the formula: int r = (int)(math.random() * (b a + 1) + a); Part 2: (Evaluate simple expression) Write a program to prompt the user to enter a simple equation with one operator (*, /, +, -, %), and two operands (decimal numbers) (Ex. 5 * 6.3 ), and output the result of the expression. Note that there can be more than one white space between operator and operands. Example: 11
12 Part 3: (English words without vowels) Write a program that reads an English word and check if it contains vowels (a, e, i, o, u). If so, output Contains vowels, else, output No vowels found. Sample Input Sample Output Java Contains vowels Sky No vowels found Hint: to delete a specific character from a string, then replace it with an empty string(""). Example: String s = "Hello World"; S = s.replaceall("rl", ""); As a result: S = "Hello Wod"; 12
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
More informationMATHEMATICAL 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
More informationCS1150 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
More informationCS5000: 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
More informationChapter 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
More informationMathematical 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
More informationMathematical 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
More informationModule 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
More informationChapter 12 Strings and Characters. Dr. Hikmat Jaber
Chapter 12 Strings and Characters Dr. Hikmat Jaber 1 The String Class Constructing a String: String message = "Welcome to Java ; String message = new String("Welcome to Java ); String s = new String();
More informationChapter 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.
More informationComputer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters
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
More informationString 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
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 character strings. All string literals in Java programs,
More informationEng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2124) Lab 2 String & Character Eng. Mohammed Abdualal String Class In this lab, you have
More informationCHAPTER 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
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All This chapter discusses class String, from the java.lang package. These classes provide the foundation for string and character manipulation
More informationAssoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Advanced Java This chapter discusses class String, class StringBuilder and class Character from the java.lang package. These classes provide
More informationChapter 8 Strings. Chapter 8 Strings
Chapter 8 Strings Chapter 6 Arrays Chapter 7 Objects and Classes Chapter 8 Strings Chapter 9 Inheritance and Polymorphism GUI can be covered after 10.2, Abstract Classes Chapter 12 GUI Basics 10.2, Abstract
More informationChapter 11 Object-Oriented Design Exception and binary I/O can be covered after Chapter 9
CHAPTER 8 STRINGS Chapter 6 Arrays Chapter 7 Objects and Classes Chapter 8 Strings Chapter 9 Inheritance and Polymorphism GUI can be covered after 10.2, Abstract Classes Chapter 12 GUI Basics 10.2, Abstract
More informationChapter 4. Mathematical Functions, Characters, and Strings
Chapter 4 Mathematical Functions, Characters, and Strings 1 Outline 1. Java Class Library 2. Class Math 3. Character Data Type 4. Class String 5. printf Statement 2 1. Java Class Library A class library
More informationEng. 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
More informationChapter 9 Strings and Text I/O
Chapter 9 Strings and Text I/O 1 Constructing Strings String newstring = new String(stringLiteral); String message = new String("Welcome to Java"); Since strings are used frequently, Java provides a shorthand
More informationCST242 Strings and Characters Page 1
CST242 Strings and Characters Page 1 1 2 3 4 5 6 Strings, Characters and Regular Expressions CST242 char and String Variables A char is a Java data type (a primitive numeric) that uses two bytes (16 bits)
More information"Hello" " This " + "is String " + "concatenation"
Strings About Strings Strings are objects, but there is a special syntax for writing String literals: "Hello" Strings, unlike most other objects, have a defined operation (as opposed to a method): " This
More informationChapter 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
More informationChapter 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.
More informationStrings. Strings and their methods. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics
Strings Strings and their methods Produced by: Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Primitive Types: char Object Types: String Primitive vs Object Types
More informationJava Strings. Interned Strings. Strings Are Immutable. Variable declaration as String Object. Slide Set 9: Java Strings and Files
Java Strings String variables are a Reference DataType Variable contains memory address of the location of string String class is used to create string objects String objects contain a string of characters
More informationProgramming with Java
Programming with Java String & Making Decision Lecture 05 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives By the end of this lecture you should be able to : Understand another
More informationChapter 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.
More informationJava Basic Datatypees
Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,
More informationStrings, characters and character literals
Strings, characters and character literals Internally, computers only manipulate bits of data; every item of data input can be represented as a number encoded in base 2. However, when it comes to processing
More informationLecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value
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
More informationComputer 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
More informationCS-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
More informationReview. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale
Review Single Pixel Filters Thresholding Posterize Histogram Equalization Negative Sepia Grayscale Spatial Filters Smooth Blur Low Pass Filter Sharpen High Pass Filter Erosion Dilation Image Processing
More informationVisual C# Instructor s Manual Table of Contents
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
More informationSTUDENT LESSON A10 The String Class
STUDENT LESSON A10 The String Class Java Curriculum for AP Computer Science, Student Lesson A10 1 STUDENT LESSON A10 The String Class INTRODUCTION: Strings are needed in many programming tasks. Much of
More informationLoops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department
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 6 Loops
More informationChapter 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
More informationBasic Computation. Chapter 2
Walter Savitch Frank M. Carrano 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
More informationB.V. Patel Institute of BMC & IT, UTU 2014
BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we
More informationWelcome to the Using Objects lab!
Welcome to the Using Objects lab! Learning Outcomes By the end of this lab: 1. Be able to define chapter 3 terms. 2. Describe reference variables and compare with primitive data type variables. 3. Draw
More informationGetting 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
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types
More informationFull 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
More informationChapter 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,
More informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,
More informationStrings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.
Strings Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and
More informationA 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;
More informationReading Input from Text File
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest
More informationCS 1301 Ch 8, Part A
CS 1301 Ch 8, Part A Sections Pages Review Questions Programming Exercises 8.1 8.8 264 291 1 30 2,4,6,8,10,12,14,16,18,24,28 This section of notes discusses the String class. The String Class 1. A String
More informationTCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.
http://www.tutorialspoint.com/tcl-tk/tcl_strings.htm TCL - STRINGS Copyright tutorialspoint.com The primitive data-type of Tcl is string and often we can find quotes on Tcl as string only language. These
More informationBasic 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
More information3 The Building Blocks: Data Types, Literals, and Variables
chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating
More informationSlide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 Advance mode: Auto
CS 170 Java Programming 1 More on Strings Working with the String class Slide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 What are Strings in Java? Immutable sequences of 0 n characters
More informationStrings in Java String Methods. The only operator that can be applied to String objects is concatenation (+) for combining one or more strings.
The only operator that can be applied to String objects is concatenation (+) for combining one or more strings. Java also provides many methods with the String class to allow us to manipulate text. These
More informationLesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types
More information4 Programming Fundamentals. Introduction to Programming 1 1
4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,
More informationCSCI 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
More informationFeatures 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
More informationMore on variables and methods
More on variables and methods Robots Learning to Program with Java Byron Weber Becker chapter 7 Announcements (Oct 12) Reading for Monday Ch 7.4-7.5 Program#5 out Character Data String is a java class
More informationOOP-Lecture Java Loop Controls: 1 Lecturer: Hawraa Sh. You can use one of the following three loops: while Loop do...while Loop for Loop
Java Loop Controls: You can use one of the following three loops: while Loop do...while Loop for Loop 1- The while Loop: A while loop is a control structure that allows you to repeat a task a certain number
More informationCreating Strings. String Length
Strings Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and
More informationJAVA 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
More informationCOMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string
COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an
More informationBasic 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
More informationJava characters Lecture 8
Java characters Lecture 8 Waterford Institute of Technology January 31, 2016 John Fitzgerald Waterford Institute of Technology, Java characters Lecture 8 1/33 Presentation outline Estimated duration presentation
More informationFull 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
More informationChapter 10: Creating and Modifying Text Lists Modules
Chapter 10: Creating and Modifying Text Lists Modules Text Text is manipulated as strings A string is a sequence of characters, stored in memory as an array H e l l o 0 1 2 3 4 Strings Strings are defined
More informationAP 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
More information10/9/2012. Computers are machines that process data. assignment in C# Primitive Data Types. Creating and Running Your First C# Program
Primitive Data Types 1. Creating and Running Your First C# Program Integer Floating-Point / Decimal Floating-Point Boolean Character String Object Declaring and Using Variables 2. Identifiers Declaring
More informationString related classes
Java Strings String related classes Java provides three String related classes java.lang package String class: Storing and processing Strings but Strings created using the String class cannot be modified
More informationOverview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O
Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.
More informationWe now start exploring some key elements of the Java programming language and ways of performing I/O
We now start exploring some key elements of the Java programming language and ways of performing I/O This week we focus on: Introduction to objects The String class String concatenation Creating objects
More informationChapter 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
More informationJava Foundations: Unit 3. Parts of a Java Program
Java Foundations: Unit 3 Parts of a Java Program class + name public class HelloWorld public static void main( String[] args ) System.out.println( Hello world! ); A class creates a new type, something
More informationTester 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
More informationWhat methods does the String class provide for ignoring case sensitive situations?
Nov. 20 What methods does the String class provide for ignoring case sensitive situations? What is a local variable? What is the span of a local variable? How many operands does a conditional operator
More informationElementary 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
More informationData 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
More informationObject oriented programming. Instructor: Masoud Asghari Web page: Ch: 3
Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning
More informationEntry 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
More informationChapter 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
More informationchar 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
More informationLanguage Fundamentals Summary
Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationJava 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
More informationJava: Learning to Program with Robots
Java: Learning to Program with Robots Chapter 07: More on Variables and Methods Chapter Objectives After studying this chapter, you should be able to: Write queries to reflect the state of an object Use
More informationChapter 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
More informationDECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.
DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special
More informationPYTHON- AN INNOVATION
PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive
More informationChapter 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
More informationStrings, Strings and characters, String class methods. JAVA Standard Edition
Strings, Strings and characters, String class methods JAVA Standard Edition Java - Character Class Normally, when we work with characters, we use primitive data types char. char ch = 'a'; // Unicode for
More informationJAVASCRIPT BASICS. JavaScript String Functions. Here is the basic condition you have to follow. If you start a string with
JavaScript String Functions Description String constants can be specified by enclosing characters or strings within double quotes, e.g. "WikiTechy is the best site to learn JavaScript". A string constant
More informationJava Overview An introduction to the Java Programming Language
Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationStrings. Upsorn Praphamontripong. Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break
Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break Strings Upsorn Praphamontripong CS 1111 Introduction to Programming Spring 2018 Strings Sequence of characters
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationChapter 2 Part 2 Edited by JJ Shepherd, James O Reilly
Basic Computation Chapter 2 Part 2 Edited by JJ Shepherd, James O Reilly Parentheses and Precedence Parentheses can communicate the order in which arithmetic operations are performed examples: (cost +
More informationThe Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II Instructor: Dr. Bowen Hui. Tuesday, April 19, 2016
First Name (Print): Last Name (Print): Student Number: The Irving K. Barber School of Arts and Sciences COSC 111 Final Exam Winter Term II 2016 Instructor: Dr. Bowen Hui Tuesday, April 19, 2016 Time: 6:00pm
More informationCS Programming I: Using Objects
CS 200 - Programming I: Using Objects Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Binary
More information