Midterm common mistakes
Upcoming SlideShare
Loading in...5
×
 

Midterm common mistakes

on

  • 918 views

 

Statistics

Views

Total Views
918
Views on SlideShare
596
Embed Views
322

Actions

Likes
0
Downloads
3
Comments
0

2 Embeds 322

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

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Midterm common mistakes Midterm common mistakes Presentation 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!