Upcoming SlideShare
×

Like this presentation? Why not share!

# Midterm common mistakes

## on Feb 21, 2014

• 918 views

### Views

Total Views
918
Views on SlideShare
596
Embed Views
322

Likes
0
3
0

### 2 Embeds322

 http://vizedhtmlcontent.next.ecollege.com 272 https://myasucourses.asu.edu 50

### Categories

Uploaded via as Microsoft PowerPoint

### Report content

• Comment goes here.
Are you sure you want to
Your message goes here

## Midterm common mistakesPresentation Transcript

• Review CST200 – Week 7: Common Mistakes in the First two Midterms Instructor: Andreea Molnar
• Outline • Division • Escape Sequences • String Methods
• Division % (remainder operator, modulus operator) - returns the remainder after dividing the second operand to the first 19 % 4 = 3 4%9=4
• Division % - the sign of the result is the sign of the numerator (first operand) -10 % 3 = -1 10 % -3 = 1
• 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
• 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
• Escape Sequences Escape sequence Meaning b backspace t tab n newline r return ’’ double quote ’ single quote backslash
• 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
• 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
• 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
• Best of luck with the exam!