1 / 11

Text

Text. Pages 102-104. Syntax Introduced. c har, String Char is single character String is a string of characters How to define them? How to assign them? How to use them?. Character data type. c har letterGrade = ‘A’; c har poorGrade = ‘F’; Usage: if (answer == ‘Y’)

winona
Download Presentation

Text

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Text Pages 102-104

  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 (inti = 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. Type conversion Pages 105-106

  6. Syntax Introduced Function for conversion: char(), int(), float(), str() Usage: inti = 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. Objects: this is a big deal Pages 107-109

  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”; intlen = 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));

More Related