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

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

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

JAVA OPERATORS GENERAL

Java Simple Data Types

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

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

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

1 Short Answer (10 Points Each)

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

Computer Science is...

Final Exam. COMP Summer I June 26, points

AP CS Unit 3: Control Structures Notes

Computer Programming, I. Laboratory Manual. Final Exam Solution

Problem Grade Total

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

Key Java Simple Data Types

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

Introduction to Computer Science Unit 2. Notes

McGill University School of Computer Science COMP-202A Introduction to Computing 1

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

Selected Questions from by Nageshwara Rao

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

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

Java Simple Data Types

CS141 Programming Assignment #6

Controls Structure for Repetition

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

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSC 1214: Object-Oriented Programming

Comp 170 Test 1 SAMPLE June 8, 2000

CSE 142, Autumn 2008 Midterm Exam, Friday, October 31, 2008

Introduction to Computer Science Unit 2. Notes

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

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

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

Chapter 4: Control structures. Repetition

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

PROGRAMMING FUNDAMENTALS

Programming with Java

Term 1 Unit 1 Week 1 Worksheet: Output Solution

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

Tutorial 06. Conditional statement: if then, if else, switch

Getting started with Java

Review for Test 1 (Chapter 1-5)

Some Sample AP Computer Science A Questions - Solutions

Final Examination Semester 2 / Year 2011

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

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

Midterm Examination (MTA)

Operators in java Operator operands.

Chapter 4: Control structures

Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

CS 177 Spring 2010 Exam I

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

Some Practice Midterm Problems

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

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

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

CS 101 Fall 2006 Midterm 3 Name: ID:

CSE 142, Summer 2013 Midterm Exam, Friday, July 26, 2013

Loops and Expression Types

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

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

NATIONAL UNIVERSITY OF SINGAPORE

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

APCS Semester #1 Final Exam Practice Problems

Introduction to Computer Science Unit 2. Exercises

AP Computer Science A Unit 2. Exercises

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

CP122 CS I. Iteration

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

Solutions to the 2005 exam

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

Arrays. Eng. Mohammed Abdualal

More types, Methods, Conditionals. ARCS Lab.

Write a program which converts all lowercase letter in a sentence to uppercase.

Visual Programming. Lecture 2: More types, Methods, Conditionals

University of Palestine. Mid Exam Total Grade: 100

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

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

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

Building Java Programs

Question 1 [20 points]

AP COMPUTER SCIENCE A

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

Nested Loops ***** ***** ***** ***** ***** We know we can print out one line of this square as follows: System.out.

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

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

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

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Building Java Programs

Repetition with for loops

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

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Lecture 6: While Loops and the Math Class

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

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

Transcription:

C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What is the type (and value) of this expression: 1!= 1 3. What is the type (and value) of this expression: 'C' - 'A' 4. What is the type (and value) of this expression: Math.sqrt(3) 5. What is the value of this expression: (9 / 4) * 4 + 9 % 4 6. What is the value of this expression: 9 % 4 == 7 % 2 7. What is the type (and value) of this expression: false (true &&! true) 8. What is the type (and value) value of this expression: 1 + 2 + "3" + 4 + 5 9. What is the type (and value) of this expression: "automaton".length() 10. What is the type (and value) of this expression: "automaton".charat(5)

11. What is the type (and value) of this expression: "automaton".substring(2, "automaton".length() - 1) 12. Write the following Java expression in mathematical notation: Math.sqrt(a + Math.sqrt(b)) 13. Write the following mathematical expression in Java notation: 14. What is the value of the following expression: 2 * 3 / 2 * 3 15. Write the following mathematical expression in Java: 16. Write the following Java expression in mathematical notation: dm = m * ((Math.sqrt(1 + v / c) / Math.sqrt(1 - v / c)) - 1); 17. What is the type (and value) of the following Java expression: 1 / 2 * 3.0 18. What is the type (and value) of the following Java expression: 1 / 2.0 * 3 19. What is the type (and value) of the following Java expression: (int) Math.sqrt( 15 ); 20. What is the output of the following line of code: System.out.println("\\\"");

21. Write a Java statement that prints the following: \n"\b\t 22. What is the output produced by the following code when embedded in a boolean x; if (true) System.out.print(0); System.out.print(1); x = (1 < 2) && (4 < 3); if (x) System.out.print(2); System.out.print(3); 23. What is the output produced by the following code when embedded in a boolean x; if (true) System.out.print(3); System.out.print(2); x = (1 < 2) (4 < 3); if (x) System.out.print(1); System.out.print(0); What if you erased the second keyword? boolean x; if (true) System.out.print(3); System.out.print(2); x = (1 < 2) (4 < 3); if (x) System.out.print(1); System.out.print(0); What if you erased them both? Please explain.

24. What is the output produced by the following code when embedded in a boolean x = false; if (true) System.out.print(0); System.out.print(1); x = x!x; if (x) System.out.print(2); System.out.print(3); 25. What is the output produced by the following code when embedded in a if (false && false true) { System.out.print(false); { System.out.print(true); 26. What is the output produced by the following code when embedded in a if (false && (false true)) { System.out.print(false); { System.out.print(true); 27. What does the following Java statement print? Why? System.out.println( 1 > 2? "what" : false ); 28. Assume two integer variables n and m. Write a boolean expression that reads like this: m is greater than n or (m + n) is divisible by 19 29. Assume that x is an integer variable. Simplify the following boolean expression: (x < 5) && (x < 25)

30. Assume that x is an integer variable. Simplify the following boolean expression: (x < 5) (x < 25) 31. Assume that x is an integer variable. Simplify the following boolean expression. Explain your simplification. (x > 3) (x < 5) 32. Assume that x is an integer variable. Simplify the following boolean expression. Explain your simplification. (x > 3) && (x < 5) 33. Consider the following code fragment when embedded in a complete program: if (x > 3) { if (x <= 5) y = 1; if (x!= 6) y = 2; y = 3; Assume that x has a value of 6 at the beginning of the fragment. What value does the variable y hold after the fragment gets executed? Why? 34. Assume int j = 3;. What happens when the following expression is executed? j = ++j + j++; 35. What is wrong with the following for loop? Why? for (int i = 0; i < 10; i = i++) { System.out.println( "Hi there." );

36. Write the following as a for loop: int count = 0; count = count + 1; while (! (count > 0)) { System.out.println( count ); count = count - 1; 37. What is the output of the following program? Explain. class One { public static void main(string[] args) { int x = 3, y = 5; int b = x++ + y++ - ++y - ++x; System.out.println( x + " " + y + " " + b ); 38. What's wrong with the following code? Explain your answer: if (2 < 1) ; { System.out.println( "Oops." ); 39. What's wrong with the following code? Explain your answer: int i = 0; while (i < 10) ; { i = i + 1; System.out.println (i); 40. Write a loop that computes: The sum of all even numbers between 2 and 100 (inclusive). 41. Write a loop that computes: The sum of all odd numbers between a and b (inclusive).

42. Rewrite the following do loop into a while loop. Explain your answer. int n = 1; double x = 0; double s; do { s = 1.0 / (n * n); x = x + s; n++; while (s > 0.01); 43. What does the following code print? Why? for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) System.out.print(i * j % 3); System.out.println(); 44. Rewrite the following for loop into a while loop. int s = 0; for (int i = 1; i <= 10; i++) s = s + 1; 45. What is the output produced by the following code when embedded in a complete program? Why? int x = 10, y = 3; while (x > 0 && y > 0) { x = x - y; System.out.print(x);

46. What gets printed when you compile and run the following program? Why? (You could try rewriting the line marked // [1] using just the operator and the numbers 1, 2, 3, 4 and 5.) public class A { public static void main(string[] args) { System.out.println(nuf(fun(5, nuf(fun(4, 3), 2)), 1)); // [1] public static int fun(int a, int b) { return a - b; public static int nuf(int b, int a) { return a - b; 47. What is the output produced by the following code when embedded in a complete program? Why? int x = 10, y = 3; while (x > 0 && y > 0) { x = x - y; y = y + 1; System.out.print(x); 48. What happens when you try to compile and run this code? Why? class One { public static void main(string[] args) { { int i = 5, j = 2; System.out.println( i + j ); { String i = "5"; char j = '2'; System.out.println( i + j );