160 Exam 2 Prep.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Chapter 8: Arrays.
CSCI 160 Midterm Review Rasanjalee DM.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Building Java Programs
1 More on Arrays and Loops Reading for this Lecture: –Section 5.4, , Break and Continue in Loops Arrays and For-each Loops Arrays and Loops.
CSCI S-1 Section 7. Coming Soon Problem Set Three, Part B – Tuesday, July 14, 17:00 EST Problem Set Four (72 + 5/15 points) – Friday, July 17, 17:00 EST.
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
EXAM 1 REVIEW. days until the AP Computer Science test.
DAY OVERLOADING.  Overloading: allows for making several methods with the same name (method heading) which differ from each other in the type.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Classes - Intermediate
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
JAVA METHODS (FUNCTIONS). Why are they called methods? Java is a strictly object-oriented programming language Methods are functions inside of objects.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
CS 160 Final Review. Name 4 primitive type variables?
Midterm preview.
Test 2 Review Outline.
CS 160 – Summer 16 Exam 1 Prep.
CS 160 Final Review.
Suppose we want to print out the word MISSISSIPPI in big letters.
Exceptions: When things go wrong
Conditional Execution
Quiz 11/15/16 – C functions, arrays and strings
Lecture Note Set 1 Thursday 12-May-05
Java Arrays. Array Object An array :a container object holds a fixed number of values of a single type. The length of an array is established when the.
Case Study 2 – Marking a Multiple-choice Test
C++ Arrays.
An Introduction to Java – Part I
Methods and Parameters
Object-Oriented Programming (OOP) Lecture No. 32
Method Mark and Lyubo.
CSC 253 Lecture 8.
Methods & Functions.
Peer Instruction 6 Java Arrays.
Building Java Programs Chapter 7
Pass by Reference, const, readonly, struct
CSC 253 Lecture 8.
CSC 113 Tutorial QUIZ I.
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
An Introduction to Java – Part I, language basics
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Introduction to Programming
Java Lesson 36 Mr. Kalmes.
Multidimensional Arrays
class PrintOnetoTen { public static void main(String args[]) {
Scope of variables class scopeofvars {
Object Oriented Programming
Suggested self-checks: Section 7.11 #1-11
Peer Instruction 4 Control Loops.
Generic Programming.
Templates Generic Programming.
Two-Dimensional Arrays
Presentation transcript:

160 Exam 2 Prep

How would I initialize an integer array named iArray with 9 elements? int iArray = new int [9]; int [] iArray = new int [9]; int [] iArray = int [9]; int iArray = 9; B

What does the console print based off the following code? public class Practice { public static void main (String [] args){ String s = “Koala Bears”; for (int i = 0; i < s.length(); i+=2) System.out.print(s.charAt(i)); } KaaBas

What would I call this method in the main method? public class Practice { public static doubleMyInt(int i) { return i * 2; } Practice prac = new Practice(); prac.doubleMyInt(9); doubleMyInt(9); doubleMyInt(); B

What would the method declaration (or header) be if I wanted a public, non-static method that takes a String as a parameter, it returns an integer. The method is called “toAscii”. public non-static int toAscii (String s) public String toAscii (int i) public int toAscii (String s) public non-static int toAscii (int i) C

What would the method declaration (or header) be if I wanted a public, static method that returns nothing, takes no parameters and is called “method1”. public void method1 (void) public static method1() public method1() public static void method1() D

What does the code print? public class Practice { public static void main (String [] args){ int i = 0; iterator(i); System.out.println(i); } public static int iterator (int i) { return i++;

What does the code print? import java.util.Arrays; public class Practice { public static void main (String [] args){ char [] s = {'a','b','c','d'}; change(s); System.out.println(Arrays.toString(s)); } public static void change(char [] s) { s[1] = ‘z’; [a, z, c, d]

Which one of these would not go to the end of String s Which one of these would not go to the end of String s? (Specify which ones cause errors and which ones are just incorrect (but they compile)? for (int i = 0; i <= s.length(); i++) for (int i = 0; i < s.length()+1; i++) for (int i = 0; i < s.length(); i++) for (int i = 0; i <= s.length() -1; i++) for (int i = 0; i < s.length() -1; i ++) A gives an error (goes one more) B gives an error (goes one more) C is correct D is correct E is incorrect only goes to the second to the last index

What would this print? import java.lang.Math; public class Practice { public static void main (String [] args){ Practice prac = new Practice(); double myDouble = 2.0; prac.cubed(myDouble); } public double cubed (double d) { return Math.pow(d, 3); Doesn’t print anything

Answers

B KaaBas C D [a, z, c, d] 8. A gives an error (goes one more) B gives an error (goes one more) C is correct D is correct E is incorrect only goes to the second to the last index 9. Doesn’t print anything