Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 PAGES 102-104 Text

2 Syntax Introduced char, String Char is single character String is a string of characters How to define them? How to assign them? How to use them?

3 Character data type char letterGrade = ‘A’; char poorGrade = ‘F’; Usage: if (answer == ‘Y’) { println(“You answered Yes”); } char letter = ‘a’;// note single quote for characters for (int i = 0; i< 26; i++){ println(letter); letter = letter + 1; }

4 Words and sentences String myName; myName = “Bina”; String firstName = “Bagger”; String lastName = “Vance”; String fullName = firstName + lastName; // here + operator means concatenation

5 PAGES 105-106 Type conversion

6 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

7 PAGES 107-109 Objects: this is a big deal

8 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

9 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()

10 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);

11 Examples (contd.) String s1 = “Mount Vernon”; String s2, s3; s2 = s1.substring(6); s3 = s1.substring(0,5); println(s1.equals(s1));

12 Text textSize(32); text("word", 10, 30); fill(0, 102, 153); text("word", 10, 60); fill(0, 102, 153, 51); text("word", 10, 90);


Download ppt "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."

Similar presentations


Ads by Google