Upcoming SlideShare
×

# Midterm common mistakes

1,326 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,326
On SlideShare
0
From Embeds
0
Number of Embeds
503
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Midterm common mistakes

1. 1. Review CST200 – Week 7: Common Mistakes in the First two Midterms Instructor: Andreea Molnar
2. 2. Outline • Division • Escape Sequences • String Methods
3. 3. Division % (remainder operator, modulus operator) - returns the remainder after dividing the second operand to the first 19 % 4 = 3 4%9=4
4. 4. Division % - the sign of the result is the sign of the numerator (first operand) -10 % 3 = -1 10 % -3 = 1
5. 5. Division / - results depend on the type of the operand • • if both operands are integers (byte, short, int, long) the result is integer, any fractional part of the result is discarded if either or both operands are floating point (float, double) the result is floating point
6. 6. Division 14 / 5 = 2 14.0 / 5 = 2.8 14 / 5.0 = 2.8 14.0 / 5.0 = 2.8 (double) 14 / 5 = 2.8 (double) (14 / 5) = 2.0 // in this case the integer division is performed first and afterwards the type casting
7. 7. Escape Sequences Escape sequence Meaning b backspace t tab n newline r return ’’ double quote ’ single quote backslash
8. 8. Escape Sequences String firstName = "Mary"; String lastName = "Smith"; System.out.println(firstName + "t" + lastName); Mary Smith System.out.println(firstName + "n" + lastName); Mary Smith System.out.println(firstName + """ + lastName); Mary"Smith System.out.println(firstName + "" + lastName); MarySmith
9. 9. String Methods String substring(int beginIndex, int endIndex) returns a substring that begins at the beginIndex and ends at the endIndex -1 String str = “Arizona State University”; str.substring (3, 5); //substring that begins at the index 3 (z) and ends at the 5-1 (o)  zo
10. 10. String Methods String indexOf (String str) returns the index of the first occurrence of str if multiple occurrences returns just the first one String str = “Arizona State University”; str.substring (“i”); //2
11. 11. Best of luck with the exam!