CS 177 Spring 2010 Exam I

Similar documents
CS 177 Spring 2009 Exam I

CS 177 Fall 2010 Exam II

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

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

Java Basic Programming Constructs

Selected Questions from by Nageshwara Rao

CMSC131. Introduction to your Introduction to Java. Why Java?

Lec 3. Compilers, Debugging, Hello World, and Variables

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

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

DATA TYPES AND EXPRESSIONS

( &% class MyClass { }

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

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

MODULE 02: BASIC COMPUTATION IN JAVA

CS 101 Fall 2005 Midterm 2 Name: ID:

Building Java Programs

King Saud University College of Computer and Information Sciences Computer Science Department

I. True/False: (2 points each)

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

Building Java Programs

Building Java Programs

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

Final Exam. COMP Summer I June 26, points

Computer Programming, I. Laboratory Manual. Final Exam Solution

Question: Total Points: Score:

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

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

Problem Grade Total

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

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

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

Term 1 Unit 1 Week 1 Worksheet: Output Solution

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Programming with Java

Question: Total Points: Score:

Date: Dr. Essam Halim

Prof. Navrati Saxena TA: Rochak Sachan

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

CIS 110 Introduction to Computer Programming. February 29, 2012 Midterm

Full file at

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Building Java Programs Chapter 2

CSE 114 Midterm 1. Please leave one seat between yourself and each of your neighbors.

Topic 4 Expressions and variables

Chapter 2: Basic Elements of Java

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

AP CS Unit 3: Control Structures Notes

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

CS 177 Fall 2010 Final Exam

Built-in data types. logical AND logical OR logical NOT &&! public static void main(string [] args)

Software Practice 1 Basic Grammar

CONDITIONAL EXECUTION

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

Java Bytecode (binary file)

Java is an objet-oriented programming language providing features that support

PROGRAMMING FUNDAMENTALS

Lecture 2: Operations and Data Types

CSCI 355 LAB #2 Spring 2004

Built-in data types. public static void main(string [] args) logical AND logical OR logical NOT &&! Fundamentals of Computer Science

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

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Introduction to Computer Science Midterm 3 Fall, Points

Building Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.

Building Java Programs Chapter 2

Data Structure and Programming Languages

CSCI 355 Lab #2 Spring 2007

Data Structure and Programming Languages

For questions 4 through 7, select the value assigned to the relevant variable, given the declarations: 3) ) This is not allowed

Full download all chapters instantly please go to Solutions Manual, Test Bank site: testbanklive.com

CIS 110 Introduction to Computer Programming Spring 2016 Midterm

Section 2.2 Your First Program in Java: Printing a Line of Text

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Some Practice Midterm Problems

1.1 Your First Program

Review for Test 1 (Chapter 1-5)

Spring 2013 COMP Midterm Exam Solutions March 07, 2013

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Question: Total Points: Score:

Chapter 3 Selection Statements

I. True/False: (2 points each)

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

CS Week 2. Jim Williams, PhD

M e t h o d s a n d P a r a m e t e r s

Full file at

Building Java Programs

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Oct Decision Structures cont d

Faculty of Science COMP-202A - Foundations of Computing (Fall 2015) - All Sections Midterm Examination

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

Prelim One Solution. CS211 Fall Name. NetID

Lecture Set 4: More About Methods and More About Operators

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

COS 126 Midterm 1 Written Exam, Fall 2009

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Place your name tag here

Transcription:

CS 177 Spring 2010 Exam I There are 25 multiple choice questions. Each one is worth 4 points. The total score for the exam is 100. Answer the multiple choice questions on the bubble sheet given. Fill in the Instructor, Course, Signature, Test, and Date blanks in the bubble sheet. For Instructor put your RECITATION INSTRUCTOR S LAST NAME GIVEN BELOW. For Course put CS 177. For Test/Quiz put 01. Fill in the bubbles that correspond to your name, section and Student ID in the bubble sheet. For your section number, use the SECTION NUMBER of your recitation section. Consult the following list: 001 FRI 07:30 LWSN B134 Parantap Roy 002 THU 09:30 BRNG B238 Wang Chen 003 FRI 03:30 LWSN 1106 Serkan Uzunbaz 004 THU 12:30 BRNG B230 Mohammad Kazi 005 THU 12:30 BRNG 1255 Parantap Roy 006 FRI 04:30 HAAS G066 Serkan Uzumbaz 019 THU 10:30 LWSN 1106 Tyler Wykoff For your student ID, use the 10 digit ID number on your student ID card. DO NOT USE YOUR SOCIAL SECURITY NUMBER! Exams without names will be graded as zero. Only the answers on the bubble sheet will be counted. The questions will be discarded. Recitation Section Number Recitation TA s Name Student Last Name Student First Name

1. We have a program named testprogram.java. Identify the correct statement about the code block. public class TestProgram public static void main() System.out.println("I am a correct program!"); A. The program will execute correctly without any changes. B. The program will execute correctly if String[] args is added to the main() method s parameter list. C. The program will execute correctly if we change the name of the file to TestProgram.java. D. The program will execute correctly if String[] args is added to the main() method s parameter list and we change the name of the file to TestProgram.java. 2. The javac compiler converts a.java program to an intermediate.class file also known as java bytecode. Identify the correct statement about java bytecode. A. Java bytecode is the same for all machines and operating systems because java is architecture and operating system independent. B. Java bytecode is the same for all machines but different for different operating systems as java is operating system dependent. C. Java bytecode is the same for all operating systems and different for different machines as java is architecture dependent. D. Java bytecode is different for all machines and operating systems because java is architecture and operating system dependent. 3. Which one of the following is a legal identifier in Java? A. 123abc B. a*b*c C. abc_123 D. abc+123

4. Which of the following methods should be used to convert a String to a double? A. Integer.parseInt() B. Integer.toString() C. Double.parseDouble() D. Double.toString() 5. Identify the correct statements for the following code and corresponding commands. public class WeAreStillTestingAProgram public static void main(string[] args) System.out.println(Double.parseDouble(args[0])); System.out.println(Double.parseDouble(args[1])); System.out.println(Double.parseDouble(args[2])); COMMAND LINE>javac WeAreStillTestingAProgram.java COMMAND LINE>java WeAreStillTestingAProgram xyz abc 12.8091 x1 A. This program produces a compilation error as there are too many arguments in the command line. B. This program produces a runtime error because the first argument cannot be converted to a double. C. This program executes correctly and the ASCII values of the first character of the strings is displayed on the screen. D. This program executes correctly with no output on the screen. 6. Based on the precedence rules for operators in Java, which of the following expressions are equivalent? (i) a + ( b * c ) - ( d / e ) (ii) ( a + b ) * ( c - d ) / e (iii) a + b * c - d / e A. (i) and (ii) B. (i) and (iii) C. (ii) and (iii) D. (i), (ii) and (iii)

7. Choose the correct output for the following code fragment: boolean abc=false; if(!abc && abc) System.out.println("0000"); if(!abc abc) System.out.println("1111"); if(!!!abc) System.out.println("2222"); System.out.println("3333"); A. 0000 B. 1111 C. 2222 D. 3333 8. Choose the correct output for the following code fragment: boolean a = true; boolean b = false; boolean c =!!(a &&!b); System.out.println("!!(" + a + " && " + "!" + b + ") = " + c); A.!!(a && true) = true B.!!(a && true) = false C.!!(true &&!false) = true D.!!(true &&!false) = false 9. What is the value of the following expression in java? 5.5 + 2 * (14 % 4 + 4) / 5 A. 7.5 B. 7.9 C. 8.5 D. None of the above

10. What does the following code do (assume both a and b have previously been declared as an int and initialized to some value)? int t = a + b; b = t - b; a = t - a; A. The program will produce a compiler error because we can t have the same variable appearing on both the sides of an equality sign. B. Leaves the value of a and b unchanged. C. Changes the sign of the values stored in a and b. D. Swaps the values of a and b. 11. Choose the correct output for the following code fragment: double a = 5/3; double b = 5.0/3.0; System.out.print("The value of a is " + a); System.out.print(" The value of b is " + b); A. The value of a is 1 The value of b is 1 B. The value of a is 1.0 The value of b is 1.6666667 C. The value of a is 1.6666667 The value of b is 1.0 D. The value of a is 1.6666667 The value of b is 1.6666667 12. What is the value of args[2] for the following command line statement? COMMAND LINE>java Alpha Beta Gamma Theta A. Alpha B. Beta C. Gamma D. Theta 13. What the decimal equivalent of the binary number 100110? A. 35 B. 36 C. 38 D. 40

14. Choose the correct output for the following code fragment: int x = 12; if (x % 3 == 0) if (x % 4 == 1) System.out.print("Aah"); if (x % 4 == 2) System.out.print("Bar"); if (x % 3 == 1) System.out.print("Foo"); System.out.print("Wow"); A. Aah B. Bar C. Wow D. Nothing is printed. 15. Choose the correct output for the following code fragment: double x = 9 / 4; if (x > 2) System.out.println("The sqaure root of 4 is " + sqrt(x) + '.'); System.out.println("Nothing calculated."); A. Nothing calculated. B. 1.50. C. 1.414. D. Nothing. There is a syntax error.

16. Choose the correct output for the following code fragment: boolean flag1 = true; boolean flag2 = false; boolean flag3 = (flag1 &&!flag2) flag2; boolean flag4 = flag1 && (!flag1 flag2); System.out.println(flag3 + ", " + flag4); A. true, true B. true, false C. false, true D. false, false 17. Some of the boolean expressions below are equivalent. Which one is NOT equivalent to the others? HINT: Make a truth table for the possible values of a and b for each expression. A. a!b B.!(!a b) C. a &&!b D. All three are equivalent. 18. Which of the following statement should we use to raise 3 to the power of 5 and assign it to a variable x? A. double x = Math.pow(3, 5); B. double x = Math.pow(5, 3); C. double x = 3 ^ 5; D. int x = Math.pow(3, 5); 19. For what data types can the operator == be used to determine whether the values of two variables of different types are equal? A. int with char B. int with boolean C. double with String D. String with String

20. Choose the correct output for the following code fragment: double x = 6.59; double y = 9.33; int x1 = Math.round(x); int x2 = (int) x; int y1 = Math.round(y); int y2 = (int) y; System.out.println((x1 + x2) + " and " + (y1 + y2)); A. 12 and 18 B. 12 and 19 C. 13 and 18 D. 13 and 19 21. Assume that a mathematician calls an integer a perfect integer if it is odd and divisible by 11. We want to create a boolean variable that is true when the int x is a perfect integer. Which statement should we use to accomplish this task? A. boolean isperfect = (x % 2 = 1) && (x % 11 = 0); B. boolean isperfect = (x / 2 = 1) && (x / 11 = 0); C. boolean isperfect = (x % 2 == 1) && (x % 11 == 0); D. boolean isperfect = (x / 2 == 1) && (x / 11 == 0);

22. Choose the correct output for the following code fragment: int x = 20, y = 10; if(x > y) if(x < 25 && y > 10) System.out.println("1111"); System.out.println("2222"); if(x < 25 && y > 10) System.out.println("3333"); System.out.println("4444"); A. 1111 B. 2222 C. 3333 D. 4444

23. Choose the correct output for the following code fragment: int x = 12; int y = 15; if(x > y) System.out.println("1111"); if(x > 10) System.out.println("2222"); if(y < 15) System.out.println("3333"); System.out.println("4444"); A. 1111 B. 2222 C. 3333 D. 4444 24. Choose the most suitable option if the following declarations were in a java program. int boolean = 123; boolean true = true; boolean false = false; A. boolean, true, and false are keywords and therefore they are illegal identifiers. B. boolean is a legal identifier. true and false are keywords and therefore they are illegal identifiers. C. true and false are legal identifiers. boolean is a primitive data type and therefore it is a illegal identifier. D. All identifiers in the code fragment are legal.

25. Choose the correct output for the following code fragment: int x = 25; int y = 15; if(x <= y) System.out.println("1111"); if(x == y) System.out.println("2222"); if(x <= 25 && y > 10) System.out.println("3333"); A. 1111 B. 2222 C. 3333 D. Nothing will be printed.