CS 180 Midterm

CS 180 Midterm - CS 180 Midterm: INDEX: int length() o...

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

View Full Document Right Arrow Icon
CS 180 Midterm: INDEX: int length() o returns the length of the calling object (which is a string) as a value of type int Sting greeting = “hello!” ------greeting.length () returns 6 Boolean equals ( other string ) o Returns true if the calling object string and the other string are equal. Otherwise returns false. String toLowerCase() and String toUpperCase() o Returns strings with the same characters as the calling objects but with letters converted to lowercase and uppercase. String trim() o Returns a string with the same characters but with leading and trailing white space removed Char charAt( Position) o Returns the character in the calling object string at the position. (counted 0,1,2,3 etc.) String word = “Hello!” Word.charAt(0) returns ‘H’ Word.charA(1) returns ‘e’ String substring ( Start ) o Returns the substring of the calling object starting from Start through to the end of the calling object. String sample = “AbcdefG” Sample.substring(2) returns “cdefG” String substring ( Start, End ) o Returns the substring of the calling object starting from Start through to the End position of the calling object. String sample = “AbcdefG” Sample.substring(2, 5) returns “cde” Int indexOf(A_String) and int indexOf(A_String, Start)----from A_string to start position o Returns the indexes (position) of the first occurance of the string A_String in the calling object string. String sample = “Hi Mary!” Sample.indexOf(“Mary) returns 3 Int lastIndexOf(A_String) o Returns the index (position) of the last occurance of the String A_String in the calling object String. Returns -1, if A_string is not found String name = “Mary, mary, mary quite so” Greeting.indexOf(“Mary”) returns 0 Name.lastIndexOf(“Mary”) returns 12 Int compareTo(A_String) o Compares the calling object string and the string argument to see which comes first in the lexicographic ordering. String entry = “adventure” Entry.compareTo(“zoo”) returns a negative number Entry.compareTo(“adventure”) returns 0 Entry.compareTo(“above”) returns a positive number String next() o Returns the next token String nextLine() o Returns the rest of the current input line. Type Name Kind of Value boolean true or false char single character short integer int integer long integer float floating-point number double floating-point number Name Java Notation Equal to == Not equal to != Greater than > Greater than or equal >= Less than < Less than or equal <= NOT ! OR || AND Remainder % x%y, remainder from division of x by y
Background image of page 1

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

View Full DocumentRight Arrow Icon
HANDOUTS: Handout 2: Scanner= “importjava.util.Scanner” DecimalFormat p = newDecimalFormat (“00.0000”); Double number = 12.3455664 System.out.println(p.format(number)); prints 12.3455 Handout 3: (Strings) finding out the length (i.e. number of characters in a string) - length() extracting a character at a certain position –
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/07/2008 for the course CS 180 taught by Professor Babian during the Spring '08 term at Bentley.

Page1 / 4

CS 180 Midterm - CS 180 Midterm: INDEX: int length() o...

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

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