// Author: Kiri Wagstaff, wkiri@cs.cornell.edu // Date: June 26, 2001 public class Lecture2 { public static void main(String[] args) { // Four basic data types: int nStudents = 51; double avgGrade = 88.3; char finalGrade = 'A'; // Single quote required boolean funClass = true; // true and false are reserved words // The following line will cause an error. (Uncomment it to see!) // int y = 5.0; // But this one is okay: (Why?) double myGrade = 90; // Strings are also useful: String myName = "Kiri"; // You can add them together (concatenation) // Don't forget to add spaces where needed String myFullName = "Kiri" + " Wagstaff"; // What if you want to put weird stuff in the string? // Use backslash (\) to "escape" characters // Double quote means 'end of string'; '\' changes the meaning. String fancyName = "Kiri \"Lou\" Wagstaff"; // This works for characters, too char quote1 = '\''; // But since chars use single quotes, this doesn't need a \: char quote2 = '"'; // Likewise, single quote does not need to be escaped in a string: String quoteString = "This is a single quote: ' "; } }