Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?

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

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Final Review.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
1 Control Structures (and user input). 2 Flow of Control The order statements are executed is called flow of control By default, statements in a method.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-1: Arrays reading: 7.1 self-checks: #1-9 videos: Ch. 7 #4.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
Lecture 11. Today’s topic Conditional statement –Relational operators –if statement –if-else statement –If-elseif statement.
Loops Chapter 4. It repeats a set of statements while a condition is true. while (condition) { execute these statements; } “while” structures.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
BUILDING JAVA PROGRAMS CHAPTER 7 Array Algorithms.
If statements Chapter 3. Selection Want to be able to do a statement sometimes, but not others if it is raining, wear a raincoat. Start first with how.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CS107 Introduction to Computer Science Java Basics.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
CSC 204 Programming I Loop I The while statement.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
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.
Chapter 5 Loops.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Working with arrays (we will use an array of double as example)
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
Lec 20 More Arrays--Algorithms. Agenda Array algorithms (section 7.5 in the book) – An algorithm is a well-defined specification for solving a problem.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Review – Final Test Chapters 8,10,11. Locate error in following statement try i = Integer.pareseInt(str); catch(NumberFormatException e) System.out.println(“Input.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Question 1a) What is printed by the following Java program? int s; int r; int i; int [] x = {4, 8, 2, -9, 6}; s = 1; r = 0; i = x.length - 1; while (i.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
The 9 th and 10 th tutoring session Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/2/2012 and 10/3/2012 -Review loop structures and improve CheckISBN and CourseAverage.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Java Review if Online Time For loop Quiz on Thursday.
Application development with Java Lecture 6 Rina Zviel-Girshin.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
Programming With Java ICS201 University Of Ha’il1 Chapter 11 Recursion.
CS-1010 Dr. Mark L. Hornick 1 Selection and Iteration and conditional expressions.
Arrays Chapter 6. Objectives learn about arrays and how to use them in Java programs learn how to use array parameters and how to define methods that.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Object Oriented Programming Lecture 2: BallWorld.
Building Java Programs Chapter 7 Arrays Copyright (c) Pearson All rights reserved.
Midterm preview.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 6 More Conditionals and Loops
Building Java Programs Chapter 4
The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression,
SELECTION STATEMENTS (1)
An Introduction to Java – Part I
LRobot Game.
An Introduction to Java – Part I, language basics
Question 1a) What is printed by the following Java program? int s;
First Semester Review.
Presentation transcript:

Review TEST 2 Chapters 4,5,7

QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?

ANSWER int

QUESTION What will be printed when the following statements are executed? Account acct1 = new Account( ); Account acct2 = new Account( ); if (acct1 == acct2) System.out.println("Equal"); else System.out.println("Not equal");

ANSWER Not equal

QUESTION What will be printed when the following statements are executed? int n = 1; System.out.print(n + " donut"); if (n >= 2); System.out.print("s");

ANSWER 1 donuts

QUESTION Write a cascaded if statement that tests the value of the variable temperature. If temperature is less than or equal to 32, the message "Freezing" should be displayed (without the quotes). If temperature is greater than or equal to 212, "Boiling" should be displayed. Otherwise, "Normal" should be displayed

ANSWER if (temperature <= 32) System.out.println("Freezing"); else if (temperature >= 212) System.out.println("Boiling"); else System.out.println("Normal");

QUESTION Show the values of the variables i and j after statements have been executed. i = 7; j = i-- * 2 + 1;

ANSWER Value of i: 6. Value of j: 15

QUESTION Assume that a is an array of integers. The following statements are supposed to search a for the number 7. Unfortunately, there is an error that prevents the statements from working. Describe the error and show how to fix it. boolean found = false; for (int i = 0; i < a.length && !found; i++) if (a[i] == 7) found = true; if (found) System.out.println("Found 7 at position: " + i);

ANSWER The variable i cannot be used after the loop terminates. It should be declared prior to the for statement.

QUESTION Use a conditional expression to combine the following statements into a single return statement: if (i >= 0) return i; return -i;

ANSWER return i >= 0 ? i : -i;

QUESTION Show the output of the following program. public class Problem54 { public static void main(String[] args) { g(62.781); g( ); } private static double f(double x) { while (x >= 10.0) x /= 10; while (x < 1.0) x *= 10; return x; } private static void g(double x) { System.out.println("f(" + x + ") = " + f(x)); }

ANSWER f(62.781) = f( ) = 8.736