Lecture03 - Variables, Constants, and Data Types Character...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Variables, Constants, and Data Types Character Strings Variables, Initialization, and Assignment Constants Primitive Data Types Reading for this class: L&L, 2.1-2.3
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Character Strings A string of characters can be represented as a string literal by putting double quotes around the text: Examples: "This is a string literal." "123 Main Street" "X" Every character string is an object in Java, defined by the String class Every string literal represents a String object
Background image of page 2
3 The println Method In the Lincoln program from Chapter 1, we invoked the println method to print a character string The System.out object represents a destination (the monitor screen) to which we can send output System.out.println ("Whatever you are, be a good one."); object method name information provided to the method (parameters)
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 The print Method The System.out object provides another method The print method is similar to the println method, except that it does not start the next line Therefore any parameter passed in a call to the print method will appear on the same line See Countdown.java (page 63) System.out.print (“Three… ”); System.out.print (“Two… ”); Prints as: Three… Two…
Background image of page 4
5 String Concatenation The string concatenation operator (+) is used to append one string to the end of another "Peanut butter " + "and jelly" It can also be used to append a number to a string A string literal cannot be broken across two lines in a program See Facts.java (page 65) System.out.println(“We present the following facts for your ” + “extracurricular edification”); NOTE: No ‘;’ here
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 String Concatenation The + operator is also used for arithmetic addition The function that it performs depends on the type of the information on which it operates If both operands are strings, or if one is a string and one is a number, it performs string concatenation If both operands are numeric, it adds them
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/25/2010 for the course CS 110 taught by Professor Wilson during the Spring '10 term at University of Massachusetts Boston.

Page1 / 21

Lecture03 - Variables, Constants, and Data Types Character...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online