Computer Programming, I. Laboratory Manual. Final Exam Solution

Similar documents
Java Bytecode (binary file)

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Arrays. Eng. Mohammed Abdualal

Practice Questions for Chapter 9

Questions Answer Key Questions Answer Key Questions Answer Key

Questions Answer Key Questions Answer Key Questions Answer Key

CS 113 PRACTICE FINAL

Computer Programming, I. Laboratory Manual. Experiment #6. Loops

An overview of Java, Data types and variables

Questions Answer Key Questions Answer Key Questions Answer Key

Date: Dr. Essam Halim

PROGRAMMING FUNDAMENTALS

Chapter 1: Introduction to Computers, Programs, and Java

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

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming: C++

CS2401 QUIZ 5 February 26, questions / 20 points / 20 minutes NAME:..

Introduction to Java & Fundamental Data Types

Programming with Java

Pace University. Fundamental Concepts of CS121 1

Chapter 8 Objects and Classes Dr. Essam Halim Date: Page 1

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

University of Palestine. Mid Exam Total Grade: 100

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

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

CIS260 Summer Exam 1 First Name Last Name: 2) is the brain of a computer. 2) A) Memory B) Hardware C) Disk D) CPU

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

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

b. Suppose you enter input from the console, when you run the program. What is the output?

Introduction to Java

Computer Programming, I. Laboratory Manual. Experiment #9. Multi-Dimensional Arrays

4 Programming Fundamentals. Introduction to Programming 1 1

Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters

Math Modeling in Java: An S-I Compartment Model

Getting started with Java

Selected Questions from by Nageshwara Rao

CCHAPTER SELECTION STATEMENTS HAPTER 3. Objectives

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Computer Programming : C++

CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:

Computer Science is...

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

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

CS260 Intro to Java & Android 03.Java Language Basics

Full file at

APCS Semester #1 Final Exam Practice Problems

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

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

Getting Started with Java. Atul Prakash

Course Outline. Introduction to java

Computer Programming, I. Laboratory Manual. Experiment #7. Methods

Oct Decision Structures cont d

Chapter 6 Arrays. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Java-Array. This tutorial introduces how to declare array variables, create arrays, and process arrays using indexed variables.

WOSO Source Code (Java)

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

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

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

CSE 114 Computer Science I

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

CS 101 Fall 2006 Midterm 3 Name: ID:

Java+- Language Reference Manual

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

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Language Reference Manual

Solutions to the 2005 exam

B.V. Patel Institute of BMC & IT, UTU 2014

VARIABLES AND TYPES CITS1001

Program Fundamentals

School of Computer Science CPS109 Course Notes 6 Alexander Ferworn Updated Fall 15. CPS109 Course Notes 6. Alexander Ferworn

Lec 7. for loops and methods

A variable is a name that represents a value. For

CONDITIONAL EXECUTION

1 Lexical Considerations

Java Basic Programming Constructs

Chapter 4 Defining Classes I

Review for Test 1 (Chapter 1-5)

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

CS 251 Intermediate Programming Methods and Classes

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

Chapter 3 Selection Statements

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Islamic University of Gaza Faculty of Engineering Computer Engineering Department

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Computational Expression

( &% class MyClass { }

Basic Operations jgrasp debugger Writing Programs & Checkstyle

CS1150 Principles of Computer Science Arrays

Lecture Set 4: More About Methods and More About Operators

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

ECOM 2324 COMPUTER PROGRAMMING II

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

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

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

Transcription:

Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Student Name: Student ID: Time: 1 hour Computer Programming, I ECOM 2005 Khaleel I. Shaheen Fall 2017 Final Exam Question 1) Choose the correct answer: 1. consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line. a. Java API b. Java language specification c. Java IDE d. Java JDK 2. Which of the following statements is correct? a. Every line in a program must end with b. Every statement in a program must end with c. Every comment line must end with d. Every method must end with a semicolon. 3. is a software that interprets Java bytecode. a. Java virtual machine b. Java compiler c. Java debugger d. Java API 4. Which of the following lines is not a Java comment? (Choose Multiple) a. /** comment */ b. // comment c. -- comment d. /* comment */ e. ** comment ** 5. A block is enclosed inside. a. parentheses b. braces c. brackets d. quotes 6. Which of the following is a valid identifier? (Choose Multiple) a. $343 b. class c. 9X d. 8+9 e. radius 7. Which of the following assignment statements is incorrect? (Choose Multiple) a. i = 1 = j = 1 = k = 1; b. i = 1; j = 1; k = 1; c. i = j = k = 1; d. i == j == k == 1; 8. Which of these data types requires the most amount of memory? a. long b. int c. short d. byte 9. -24 % -5 is a. -1 b. -4 c. 4 d. 0 1

10. What is x after the following statements? int x = 2; int y = 1; x *= y + 1; a. x is 1. b. x is 2. c. x is 3. d. x is 4. 11. Which of the following expressions will not yield 0.5? a. 1.0 / 2 b. (double) (1 / 2) c. (double) 1 / 2 d. 1 / 2.0 12. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 13. A Java character is stored in. a. one byte b. two bytes c. three bytes d. four bytes 14. The Unicode of 'a' is 97. What is the Unicode for 'c'? a. 96 b. 97 c. 98 d. 99 15. '3' - '2' + 'm' / 'n' is. a. 0 b. 1 c. 2 d. 3 16. Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to. a. 66 b. B c. A1 d. error 17. In Java, the word true is. a. a Java keyword b. a Boolean literal c. same as value 1 d. same as value 18. Analyze the following code: boolean even = false; if (even = true) { System.out.println("It is even!"); a. The program has a compile error. b. The program has a runtime error. c. The program runs, but displays nothing. 19. Assume x = 4 and y = 5, Which of the following is true? 0 d. The program runs and displays "It is even!". a. x < 5 && y < 5 b. x < 5 y < 5 c. x > 5 && y > 5 d. x > 5 y > 5 2

20. Suppose x=10, y=10 what is x after evaluating the expression (y > 10) && (++x > 10). a. 9 b. 10 c. 11 d. other 21. In Java, the names of parameters and arguments must be the same. a. True b. False 22. In an infinite while loop, the loop condition is initially false, but after the first iteration, it is always true. a. True b. False 23. "abc".compareto("aba") returns. a. 1 b. 2 c. -1 d. -2 24. Assume int[][] x = {{1, 2, {3, 4, {5, 6, what are x.length and x[0].length? a. 3 and 2 b. 2 and 3 c. 3 and 3 d. 2 and 1 25. is a construct that defines objects of the same type. a. A class b. An object c. A method d. A data field 26. Which of the following statements are true? (choose multiple) a. Multiple constructors can be defined in a class. b. Constructors do not have a return type, not even void. c. Constructors must have the same name as the class itself. 27. Variables that are shared by every instance of a class are. d. Constructors are invoked using the new operator. a. public variables b. private variables c. instance variables d. static variables 28. A method that is associated with an individual object is called. a. static method b. class method c. instance method d. object method 29. is invoked to create an object. a. new operator b. constructor c. main method d. method with a return type 30. Exam Difficulty? a. b. c. Multiple Questions Answer Sheet: 1 2 3 4 5 6 7 8 9 10 D B A CE B AE AD A B D 11 12 13 14 15 16 17 18 19 20 B D B D B C B D B B 21 22 23 24 25 26 27 28 29 30 B B B A A ABCD D C B A, B, C 3

Question 2) Print the output for every code snippet below: Code int x = 3; int y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; System.out.println(y); char ch = 'b'; switch (ch) { case 'a': case 'b': case 'c': case 'd': boolean even = false; System.out.println( (even? "true" : "false") ); for (int i = 1; i <= 10; i++){ System.out.print(i + " "); i++; int[] mylist = {1, 2, 3, 4, 5, 6; for (int i = mylist.length - 2; i >= 0; i--){ mylist[i + 1] = mylist[i]; for (int e: mylist) System.out.print(e + " "); int[][] matrix = {{1, 2, 3, 4, {4, 5, 6, 7, {8, 9, 10, 11, {12, 13, 14, 15; for (int i = 0; i < 4; i++) System.out.print(matrix[i][1] + " "); class Foo { int i; static int s; public static void main(string[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); public Foo() { i++; s++; Good Luck Output 2 bbb false 1 3 5 7 9 1 1 2 3 4 5 2 5 9 13 f1.i is 1 f1.s is 1 f1.i is 1 f1.s is 2 f1.i is 1 f1.s is 3 4