PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of...
-
Upload
juniper-wilcox -
Category
Documents
-
view
212 -
download
0
Transcript of PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of...
![Page 1: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/1.jpg)
PAGES 102-104
Text
![Page 2: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/2.jpg)
Syntax Introduced
char, String
Char is single characterString is a string of characters
How to define them? How to assign them? How to use them?
![Page 3: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/3.jpg)
Character data type
char letterGrade = ‘A’;char poorGrade = ‘F’;
Usage: if (answer == ‘Y’) { println(“You answered Yes”); }
char letter = ‘a’;// note single quote for charactersfor (int i = 0; i< 26; i++){ println(letter); letter = letter + 1;}
![Page 4: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/4.jpg)
Words and sentences
String myName; myName = “Bina”;
String firstName = “Bagger”;String lastName = “Vance”;String fullName = firstName + lastName; // here + operator means concatenation
![Page 5: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/5.jpg)
PAGES 105-106
Type conversion
![Page 6: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/6.jpg)
Syntax Introduced
Function for conversion: char(), int(), float(), str()
Usage: int i = 65 ; // value of character A char ch1; ch1 = char(i); assigns ch1 = ‘A’ float fNum = 65.3; int j = (int)fNum; // convert floating point number to integer
![Page 7: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/7.jpg)
PAGES 107-109
Objects: this is a big deal
![Page 8: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/8.jpg)
What is an object?
Unlike simple/basic data types that have only name and value, objects have name, characteristics, and operations.
You define an object by Its name or id or reference Its characteristics /properties: it has ____, ____ Its operations: It can do _____, _____
Dot notation lets you access the operations of an object as well any publicly accessible characteristics/properties
![Page 9: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/9.jpg)
Object String
String has a number of chars assigned to it.What are the operations?length() startsWith(char)charAt(int)subString(int)subString(int, int)equals()
![Page 10: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/10.jpg)
Examples for String Object operations
String s1 = “Player Piano”;int len = s1.length();println(len);
println(s1.startsWith(‘P’));println(s1.startsWith(‘Q’));
char fifth;fifth = s1.charAt(5);
![Page 11: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/11.jpg)
Examples (contd.)
String s1 = “Mount Vernon”;String s2, s3;s2 = s1.substring(6);s3 = s1.substring(0,5);
println(s1.equals(s1));
![Page 12: PAGES 102-104 Text. Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How.](https://reader036.fdocuments.us/reader036/viewer/2022072006/56649f455503460f94c664dd/html5/thumbnails/12.jpg)
Text
textSize(32); text("word", 10, 30); fill(0, 102, 153); text("word", 10, 60); fill(0, 102, 153, 51); text("word", 10, 90);