2.0.printabletypes

2.0.printabletypes - In This Section… Strings Text Words...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 201 – Elementary Computer Programming 1 CSE 201 Strings & More I/O CSE 201 – Elementary Computer Programming 2 In This Section… ! Strings ! Text: Words, Sentences, etc… ! Additional I/O Information CSE 201 – Elementary Computer Programming 3 The char Type ! A variable of the char data type stores a single “printable” character ! A char constant or literal is a character in single quotes, e.g., ‘y’ ! For example: char answer = ‘y’; System.out.println(answer); prints (displays) the letter y CSE 201 – Elementary Computer Programming 4 The String Type ! A string is a sequence of characters ! The String type is used to declare variables that store strings ! The String type is not a primitive type: it is known as a class or reference type ! A String constant is one or more characters in double quotes, e.g., “string constant” ! Examples: char charVariable = ‘a’;//single quotes String stringVariable = "a";//double quotes String sentence = "Hello, world"; See Also Section 2.9 is a good introduction to the String class. CSE 201 – Elementary Computer Programming 5 String Variables ! Declare a String variable: String greeting; ! Assign a value to the variable: greeting = "Hello!"; ! Use the variable as a String argument in a method call: System.out.println(greeting); causes the string Hello! to be displayed on the screen CSE 201 – Elementary Computer Programming 6 Indexing Characters Within a String !
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern