2008pt2 - Examples problem-return a reverse join of strings...

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

View Full Document Right Arrow Icon
String it’s a class string s; string s1, s2 ,s3; s1=”Hello, world”; s2=s1; remember strings are objects and use reference semantics s3= “Hello, “ + “world”; (s1==s2)>true (s2==s3)> false *s1.equals (s2)> true while (!cmd.equals(“quit”)){…} while(!”quit”!.equals(cmd)) {…. .} s1.compareTo(s2) > int (-1, 0, +1) < = > s.length() > int s.char(i) > char a string is an array of characters in order s.substring (start,end) > string “abcdefg”.substring (,5) > “de”
Background image of page 1

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

View Full Document Right Arrow Icon
always off by one (the end is really one more than the actual end, java error, get used to it!!!! s.substring (start) > string [s.substring (start, s.length())] s.tolowercase() > string s.uppercase() > string s.trim() > string s.indexof © > int s.lastindexof (c) > int Double.parseDouble(s) > double Integer.parseInt (s) > int Character Character.isDigit (c) > Boolean Character.isLetter (c) > Boolean Character.isUppercase > Boolean Character.toUppercase (c) > char
Background image of page 2
Background image of page 3

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

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

Unformatted text preview: Examples problem-return a reverse join of strings English- reverse string>string set result to null string for each character in s (from the last to the first) append the current character to the result return result Java-public static string reverse (string s) [ string result = “” for (int I = s.length()-1 I >= 0; i--) [ ] return resl=ult; ] problem – determine if a string, s, is a palindrome English- is Pailindrome ; string > boolean low< :index of 1 st char in S high< index of last char in s as long as < high: if char at index low in S does not equal char at index high in S: return false otherwise increment low decrement high return true Java- public static Boolean is Palindrome (string s) [ int low = 0 int high = 0 s.length ()-1; while (low < high) [ if (s.charAt(low)!=s.scharAt(high))[ return false; }else} ++low;--high; } } return true; } Java.sun.com (api’s)...
View Full Document

{[ snackBarMessage ]}

Page1 / 4

2008pt2 - Examples problem-return a reverse join of strings...

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

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