Michele Weigle - COMP 14 - Spr 04

Slides:



Advertisements
Similar presentations
CS110 Programming Language I
Advertisements

Μαθαίνοντας Python [Κ4] ‘Guess the Number’
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
1 Introduction to Recursion  Introduction to Recursion  Example 1: Factorial  Example 2: Reversing Strings  Example 3: Fibonacci  Infinite Recursion.
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
Chapter 8 ARRAYS Continued
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
1 CSC 221: Computer Programming I Spring 2010 Design & text processing  design principles  cohesion & coupling  objects vs. primitives  String methods:
1 CS 177 Week 3 Recitation Slides Basic Math Operations, Booleans, and Character Operations.
COMP 110 Objects and references Luv Kohli October 8, 2008 MWF 2-2:50 pm Sitterson 014.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
1 More data types Character and String –Non-numeric variables –Examples: char orange; String something; –orange and something are variable names –Note.
Iterative Statements Introduction The while statement The do/while statement The for Statement.
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
COMP 110 More loops Luv Kohli September 15, 2008 MWF 2-2:50 pm Sitterson
A: A: double “4” A: “34” 4.
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Strings and I/O. Lotsa String Stuff… There are close to 50 methods defined in the String class. We will introduce several of them here: charAt, substring,
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
COMP 110 More arrays, 2D arrays, Program 4 Luv Kohli November 10, 2008 MWF 2-2:50 pm Sitterson 014.
COMP 110 Arrays Luv Kohli November 5, 2008 MWF 2-2:50 pm Sitterson 014.
Loops ( while and for ) CSE 1310 – Introduction to Computers and Programming Alexandra Stefan 1.
COMP 110 Some more about objects and references Luv Kohli October 10, 2008 MWF 2-2:50 pm Sitterson 014.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 21, 2011
while Repetition Structure
COMP 110 More arrays, 2D arrays, Program 4
COMP 14 Introduction to Programming
Michele Weigle - COMP 14 - Spr 04 Catie Welsh March 30, 2011
Start reading Sec and chapter 7 on loops
Tutorial 8 Pointers and Strings
CS305J Introduction to Computing
CS 1428 Exam I Review.
Midterm Review Problems
Agenda Warmup Lesson 2.5 (Ascii, Method Overloading)
COMP 110 Some notes on inheritance, review
Review Operation Bingo
CS 177 Week 3 Recitation Slides
CS 106A, Lecture 9 Problem-Solving with Strings
Michele Weigle - COMP 14 - Spr 04
COMP 110 Information hiding and encapsulation
Testing change to a linked list
An Introduction to Java – Part I, language basics
CS 1430: Programming in C++ No time to cover HiC.
COMP 110 Loops, loops, loops, loops, loops, loops…
Chapter (3) - Looping Questions.
Unit 3 - The while Loop - Extending the Vic class - Examples
Michele Weigle - COMP 14 - Spr 04
Code Refresher Test #1 Topics:
Loops.
Michele Weigle - COMP 14 - Spr 04 Catie Welsh February 14, 2011
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
CS 1428 Exam I Review.
Lecture 20 – Practice Exercises 4
Announcements Lab 5 due Wednesday at noon.
COMPUTING.
Introduction to Python
Presentation transcript:

Michele Weigle - COMP 14 - Spr 04 COMP 110 Midterm review Luv Kohli October 27, 2008 MWF 2-2:50 pm Sitterson 014

Michele Weigle - COMP 14 - Spr 04 Announcements Program 3 due Friday, October 31, 2pm

Michele Weigle - COMP 14 - Spr 04 Questions? Any other questions?

Michele Weigle - COMP 14 - Spr 04 Today in COMP 110 Take out a sheet of paper Write your name on it Take about 5 minutes to write down how you think you did on the midterm, and why

Midterm scores Average score: ~76

Q3 a. double var1 = 9 / 2; b. int var2 = (int) (6.6 / 3.0) 9 / 2 is integer division, resulting in 4 division is done before the automatic typecast to double. var1 is set equal to 4, or 4.0 b. int var2 = (int) (6.6 / 3.0) 6.6 / 3.0 is 2.2 (int) 2.2 is 2 var2 is set to 2 c. float var3 = (float) 5 / 2 (float) 5 / 2 causes 2 to be typecast to float (float) 5 / (float) 2 is 2.5 var3 is set to 2.5

Q4 Accepted most reasonable things as long as they were not too far off

Q8 3 * 4 * 3 = 36  3 iterations  4 iterations  3 iterations int i = 0; while (i < 3) { for (int j = 1; j <= 4; j++) for (int k = 3; k > 0; k--) System.out.println(i + “,” + j + “,” + k); } i++; 3 * 4 * 3 = 36  3 iterations  4 iterations  3 iterations

Q13: Tracing code the magical snail quickly eats the strange airplane NAM NAM NAM!!!

Q15: Remove middle words Y o u w i l n t g ! 1 2 3 4 5 6 7 8 9 10 11 int firstSpace = str.indexOf(“ ”); int lastSpace = str.lastIndexOf(“ ”); String strNoMiddle = str.substring(0, firstSpace) + str.substring(lastSpace); Y o u w i l n t g ! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Y o u g ! 1 2 3 4 5 6

Q16: Determining if a string is a palindrome Odd-length string r a c e 1 2 3 4 5 6

Q16: Determining if a string is a palindrome Even-length string r e d 1 2 3 4 5

Q16: Determining if a string is a palindrome ‘u’ != ‘e’ Not a palindrome r u d e 1 2 3 4 5

Q16: Determining if a string is a palindrome Need a loop What is being repeated? Character comparison What characters are we comparing? First half of string to reverse of second half of string What is our loop terminating condition? We find a pair of characters that do not match

Q16: using a for loop r a c e 1 2 3 4 5 6 i str.length() – 1 - i public boolean isPalindrome(String str) { for (int i = 0; i < str.length() / 2; i++) if (str.charAt(i) != str.charAt(str.length() – 1 – i)) return false; } return true; r a c e 1 2 3 4 5 6

Q16: Can also do it with a while loop public boolean isPalindrome(String str) { int first = 0; int last = str.length() - 1; while (first < last) if (str.charAt(first) != str.charAt(last)) return false; } first++; last--; return true;

Michele Weigle - COMP 14 - Spr 04 Wednesday Static variables and methods