CS180. Exam 1 Review

Similar documents
I. True/False: (2 points each)

University of Palestine. Mid Exam Total Grade: 100

PROGRAMMING FUNDAMENTALS

JAVA OPERATORS GENERAL

CS 101 Exam 2 Spring Id Name

Prof. Navrati Saxena TA: Rochak Sachan

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Computer Programming, I. Laboratory Manual. Final Exam Solution

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

CS Week 5. Jim Williams, PhD

CS170 Introduction to Computer Science Midterm 2

Operators Questions

Selenium Class 9 - Java Operators

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CS 101 Fall 2005 Midterm 2 Name: ID:

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

More on methods and variables. Fundamentals of Computer Science Keith Vertanen

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

ESC101 : Fundamental of Computing

AP COMPUTER SCIENCE A

CS 201, Fall 2016 Sep 28th Exam 1

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Java Basic Programming Constructs

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

Spring University of New Mexico CS152 Midterm Exam. Print Your Name

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

Loops. CSE 114, Computer Science 1 Stony Brook University

Following is the general form of a typical decision making structure found in most of the programming languages:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

CS 102/107 - Introduction to Programming Midterm Exam #2 - Prof. Reed Spring 2011

Question: Total Points: Score:

Programming Basics. Digital Urban Visualization. People as Flows. ia

Java Programming for Selenium

Computer Science II (20082) Week 1: Review and Inheritance

CS111: PROGRAMMING LANGUAGE II

CIS October 16, 2018

JAVA Programming Language Homework II Student ID: Name:

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Key Java Simple Data Types

Selected Questions from by Nageshwara Rao

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

Final Examination Semester 2 / Year 2011

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

University of Massachusetts Amherst, Electrical and Computer Engineering

CIS March 1, 2018

CS 101 Spring 2007 Midterm 2 Name: ID:

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2010

Handout 4 Conditionals. Boolean Expressions.

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

CS 170 Exam 1. Version: B Fall Name (as on OPUS):

Java Simple Data Types

Midterm Examination (MTA)

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

Place your name tag here

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

CMP 326 Midterm Fall 2015

CS 302 Week 9. Jim Williams

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

CS 231 Data Structures and Algorithms, Fall 2016

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

CS 170 Exam 1. Version: C Fall Name (as on OPUS):

Practice Midterm 1. Problem Points Score TOTAL 50

CMPS 11 Intermediate Programming Midterm 2 Review Problems

CIS October 19, 2017

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

CS 106 Introduction to Computer Science I

DM503 Programming B. Peter Schneider-Kamp.

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

I. True/False: (2 points each)

CS 520 Theory and Practice of Software Engineering Fall 2017

Expressions & Flow Control

The Java language has a wide variety of modifiers, including the following:

Introduction to Java

1 Short Answer (10 Points Each)

Name Section Number. Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson

CONDITIONAL EXECUTION

CP122 CS I. Iteration

CS212 Midterm. 1. Read the following code fragments and answer the questions.

Lecture 5: Methods CS2301

Java Programming Language. 0 A history

Lecture Set 4: More About Methods and More About Operators

Introduction to Computer Science Unit 2. Notes

AP Computer Science Unit 1. Programs

Arrays. COMS W1007 Introduction to Computer Science. Christopher Conway 10 June 2003

Prelim 1. CS 2110, 13 March 2018, 5:30 PM Total Question Name Short answer

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Transcription:

CS180 Exam 1 Review

What is the output to the following code? System.out.println("2 + 2 = " + (2 + 2)); System.out.println("2 + 2 = " + 2 + 2);

What is the output to the following code? System.out.println(String.valueOf(15+20)); System.out.println(String.valueOf("15+20"));

Evaluate the following values. byte val1 = Byte.MIN_VALUE; int val2 = Integer.MIN_VALUE - 1; double val3 = 3 + 4; int val4 = 3 / 4; int val5 = 3 + 4.5;

What is the output to the following code? int point = 15; switch (point) case 0: System.out.println( point is 0 ); break; case 15: System.out.println( point is 15 ); case 30: System.out.println( point is 15 or 30 ); break; case 40: System.out.println( point is 40 ); default: System.out.println( Invalid point );

What is the output to the following code? double rate = 1.5; double price = 0.0; if (rate >= 0.0 && rate < 1.0) price = 20 * rate; else if (rate >= 1.0 && rate < 2.0) price = 15 * rate; else if (rate >= 2.0) price = 10 * rate; System.out.println(price);

What is the output to the following code? int y = 100, x = 5; while (y > 0) y--; if (y % x!= 0) continue; System.out.println(y);

What is the output to the following code? for (int k = 1, g = 4; k++ < g; --g) System.out.print(k + " " + g + " ");

What is the output to the following program? public class ConsExample int value; public ConsExample(int v) this.value = v; public static void main(string args[]) ConsExample ce1 = new ConsExample(10); ConsExample ce2 = new ConsExample(10); if (ce1 == ce2) System.out.println("True"); else System.out.println("False");

What is the output to the following program? public class ConsExample public ConsExample() System.out.println("A"); public void sample(string eg) System.out.println(eg); ConsExample ce1 = new ConsExample(); System.out.println("B"); public static void main(string args[]) ConsExample ce1 = new ConsExample(); ce1.sample("c");

What is the output to the following program? public class ConsExample int value; public ConsExample() value = 10; System.out.println(value); public void func1() ConsExample ce2 = new ConsExample(); ce2.value = 20; System.out.println(this.value); ce2.func2(); public void func2() System.out.println(this.value); public static void main(string args[]) ConsExample ce1 = new ConsExample(); ce1.value = 20; System.out.println(ce1.value); ce1.func1();

What is the output to the following program? public class Puzzle private int x; public Puzzle() x = 0; public void f(int x, int y) x = y++; this.x = x * ++y; public void g(int x, int y) x = y * y; y = this.x; public int getx() return x; public static void main(string args[]) Puzzle p = new Puzzle(); int x = 5; int y = 6; p.f(); p.g(); System.out.println( x= + x +, y= + y +, p.getx()= + p.getx());

What are two examples of interfaces (the Java definition) in your every day life? Discuss how your examples are examples of interfaces.

What is the output to the following code snippets? public interface Sleeper public void wakeup(); public class TiredSleeper implements Sleeper public void wakeup() System.out.println( Ehhh ); Sleeper[] sleepers = new Sleeper[2]; sleepers[0] = new TiredSleeper(); sleepers[1] = new RestedSleeper(); for (int k=0; k<2; k++) sleepers[k].wakeup(); public void ignorealarm() System.out.println( Go away ); TiredSleeper sleeper = new TiredSleeper(); sleeper.ignorealarm(); Sleeper sleeper = new TiredSleeper(); sleeper.ignorealarm(); public class RestedSleeper implements Sleeper public void wakeup() System.out.printn( Ready for the day! );

Write a function which takes in an array of integers and returns true if each successive value in the array is at least twice the previous value in the array. For example 2, 4, 9, 12 returns false (12 < 9*2) 2, 4, 9, 25 returns true. public boolean arraydoublesup(int[] nums)

Write a function which takes in an array of integers and returns true if each successive value in the array is at least twice the previous value in the array. For example 2, 4, 9, 12 returns false (12 < 9*2) 2, 4, 9, 25 returns true. public boolean arraydoublesup(int[] nums) // check the argument for completeness, just do something reasonable if (nums == null) return false; for (int k=1; k<nums.length; k++) if (nums[k] < 2*nums[k-1]) return false; return true;

Write a function which takes in two arrays one a set of integers (nums) and the other a set of potential factors (factors) and computes the number of integers in numswhich has at least one factor in factors. For example, if: nums= 2, 4, 9, 12, 15, 25 factors = 3, 5 Then numintegerswithfactors(nums, factors) would return 4 (for the 9, 12, 15, and 25). public int numintegerswithfactors(int[] nums, int[] factors)

Write a function which takes in two arrays one a set of integers (nums) and the other a set of potential factors (factors) and computes the number of integers in numswhich has at least one factor in factors. For example, if: nums= 2, 4, 9, 12, 15, 25 factors = 3, 5 Then numintegerswithfactors(nums, factors) would return 4 (for the 9, 12, 15, and 25). public int numintegerswithfactors(int[] nums, int[] factors) // check the arguments for completeness if (nums == null factors == null) return 0; int numdivisible = 0; for (int k=0; k<nums.length; k++) for (int i=0; i<factors.length; i++) if (nums[k] % factors[i] == 0) numdivisible++; break; return numdivisible;