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

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

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

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

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

Lara Technologies Special-Six Test

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

d. If a is false and b is false then the output is "ELSE" Answer?

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

CS 152 Computer Programming Fundamentals The if-else Statement

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

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

CS180. Exam 1 Review

AP COMPUTER SCIENCE A

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

1.Which four options describe the correct default values for array elements of the types indicated?

There are four variables declared. They are named pearprice, pearcost, pearsales, and profit.

Repetition with for loops

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

THE UNIVERSITY OF AUCKLAND

Introduction to Computer Science Unit 2. Exercises

Concurrency Quiz: Java Threads

CSE 8A Lecture 21. SMarx extra final exam office hours Fri 3/15 11:15am-1pm EBU-3B #2206

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, Instructions

Computer Programming, I. Laboratory Manual. Final Exam Solution

ECE Fall 20l2, Second Exam

CIS March 1, 2018

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

Chapter 3. Selections

AP CS Unit 3: Control Structures Notes

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

CS 112 Introduction to Programming

Question: Total Points: Score:

6 COMPUTER PROGRAMMING

CIS October 19, 2017

Topic 6 Nested for Loops

CS 112 Introduction to Programming

AP CS Unit 8: Inheritance Exercises

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

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

CSCI 201L Written Exam #1 Fall % of course grade

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.

Some Practice Midterm Problems

Lec 7. for loops and methods

ECE 462 Fall 2011, Second Exam

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

CS 170 Section 3, Spring 2015 Programming in Java Midterm Exam 1. Name (print):

CS 101 Exam 2 Spring Id Name

Final Examination Semester 2 / Year 2012

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

CS 101 Fall 2005 Midterm 2 Name: ID:

int x = 42, y = 33; //1 int z = x + y; //2 System.out.println(x + "+" + y + "=" + z); //3

Operators Questions

Recitation: Loop Jul 7, 2008

Tutorial 8 Date: 15/04/2014

CS141 Programming Assignment #6

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

Question: Total Points: Score:

true false Imperative Programming III, sections , 3.0, 3.9 Introductory Programming Control flow of programs While loops: generally Loops

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

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

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

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

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

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

CS-259 Computer Programming Fundamentals Arrays

Chapter 1: Introduction to Computers, Programs, and Java

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

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

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

SAMPLE QUESTIONS FOR DIPLOMA IN INFORMATION TECHNOLOGY; YEAR 1

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

CSE 142, Autumn 2011 Midterm Exam: Friday, November 4, 2011

AP CS Unit 6: Inheritance Exercises

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

CS 170 Exam 2. Version: A Spring Name (as in OPUS) (print): Instructions:

Recap: Assignment as an Operator CS 112 Introduction to Programming

ECE Fall 2018, Test 3

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

CIS October 16, 2018

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

CSE 142 Sample Midterm Exam #3

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Polymorphism CSCI 201 Principles of Software Development

I. True/False: (2 points each) On your bubble form fill out a for true and b for false.

Building Java Programs

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

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

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

COMP 110/L Lecture 6. Kyle Dewey

CS Week 5. Jim Williams, PhD

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

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

Place your name tag here

TESTING AND DEBUGGING

Assignment 2.4: Loops

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

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

CIS 110 Introduction To Computer Programming. October 5th, 2011 Exam 1. Answer key

public class MaxSeq { public static Node maxs (int[] table){ int count = 0; Node[] nodes = new Node[table.length]; Node n = new Node(table[0],1,1);

Transcription:

Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once you start the exam, you may not leave the room until you turn it in. After turning in the exam, you may not continue work on it. Write answers on exam. You may use extra paper which you may turn in or keep, as you see fit. Time Limit: 75 minutes. 1) This Java program compiles and runs. What is the output? 1) public class IfLogic 5) int r = 190; 6) int g = 11; 7) int b = 270; 8) if (r > 150) 9) { System.out.print("Fo"); 10) } 11) else if (g > 200) 1 System.out.print("Go"); 14) else if (b > 200) 15) { System.out.print("Ho"); 16) } 17) if (g > r) 18) { System.out.print("Lo"); 19) } 20) else if (b > r) 21) { System.out.print("Mo"); 22) } 23) else if (g < b) 2 System.out.print("Yo"); 25) } 26) else if (r < b) 27) { System.out.print("Zo"); 28) } 29) } 30) } - 1 of 10 -

2) This Java program compiles and runs. What is the output? 1) public class IfAndOr 5) int r = 117; 6) int g = 107; 7) int b = 227; 8) if (r < 200 && g < 200 && b < 200) 9) { System.out.print("Gu"); 10) } 11) if (r < 200 (g < 200 && b < 200)) 1 System.out.print("Fu"); 14) if (r < 200 g < 200 b < 200) 15) { System.out.print("Bu"); 16) } 17) if (r < 200 && (g < 200 b < 200)) 18) { System.out.print("Mu"); 19) } 20) if (r < 99 (g < 99 && b < 99)) 21) { System.out.print("Lu"); 22) } 23) } 24) } - 2 of 10 -

3) This Java program compiles and runs. What is the output? 1) public class IfNest 5) int r = 144; 6) int g = 211; 7) int b = 27; 8) if (r > 100) 9) { System.out.print("B"); 10) if (g > 200) System.out.print("C"); 11) else if (b > 200) System.out.print("D"); 12) else System.out.print("E"); 13) System.out.print("F"); 14) } 15) else if (r > 150) 16) { System.out.print("G"); 17) if (g < 100) System.out.print("H"); 18) else if (b < 100) System.out.print("I"); 19) else System.out.print("J"); 20) System.out.print("K"); 21) } 22) else if (b < 100) 23) { System.out.print("L"); 24) if (g < 200) System.out.print("M"); 25) else if (r < 200) System.out.print("N"); 26) else System.out.print("O"); 27) } 28) if (g > 100) 29) { System.out.print("P"); 30) if (r > 0 ) System.out.print("Q"); 31) } 32) else if (b > 100) System.out.print("R"); 33) else if (g > 100) 3 System.out.print("S"); 35) if (r > 0 ) System.out.print("T"); 36) else System.out.print("W"); 37) System.out.print("X"); 38) } 39) } 40) } - 3 of 10 -

4) This Java program compiles and runs. What is the output? 1) public class LoopWithModulus 5) int n = 225; 6) int z = 3; 7) while (n > 1) 8) { 9) if ((n % z) == 0) 10) { 11) System.out.print(z + " "); 12) n = n / z; 14) else z = z + 2; 15) } 16) } 17) } - 4 of 10 -

5) This Java program compiles and runs. What is the output? 1) public class LoopWithString 5) String foo = "Seth832Richey17"; 6) int n = -1; 7) char c = 'x'; 8) 9) while (!Character.isDigit(c)) 10) { System.out.println("n="+ n + "*"); 11) n++; 12) c = foo.charat(n); 14) 15) while (Character.isDigit(c)) 16) { System.out.println("n="+ n + ", c=" + c ); 17) n++; 18) if (n >= foo.length()) break; 19) c = foo.charat(n); 20) } 21) } 22) } - 5 of 10 -

6) This Java program compiles and runs. What is the output? 1) public class LoopNest 5) for (int i=0; i<20; i=i+5) 6) { 7) for (int k=i; k<=i*3; k=k+10) 8) { 9) System.out.print(" " + k); 10) } 11) System.out.println("<===== i=" + i); 12) } 14) } - 6 of 10 -

7) This Java program compiles and runs. What is the output? 1) public class MethodPower 3) public static int foo(int a) 5) int b = a / 10; 6) int c = a % 10; 7) System.out.println("a="+ a + ", b="+ b + ", c=" + c); 8) for (int i=b; i<=c; i++) 9) { System.out.println(i + " "); 10) if (b == c) return i; 11) } 12) return c; 14) 15) 16) public static void main(string[] args) 17) { 18) int a=25, b=52, c=44; 19) System.out.println("foo=" + foo(a)); 20) System.out.println("foo=" + foo(b)); 21) System.out.println("foo=" + foo(c)); 22) } 23) } - 7 of 10 -

8) This Java program compiles and runs. Assume the CS-152 Picture class is in the same directory as this class. What is the output? 1) import java.awt.graphics; 2) import java.awt.color; 3) 4) public class WonderDraw 5) { 6) public static void main(string[] args) 7) { 8) Picture bob = new Picture(401, 401); 9) Graphics canvas = bob.getoffscreengraphics(); 10) canvas.setcolor(color.red); 11) int a = 0; 12) for (int x=0; x<=400; x=x+40) 13) { 14) //drawline(x1, y1, x2, y2) 15) if (x == 200) a = 400; 16) canvas.drawline(a, 200, 200, x); 17) } 18) bob.repaint(); 19) } 20) } - 8 of 10 -

9) This Java program compiles and runs. What is the output? 1) import java.awt.graphics; 2) import java.awt.color; 3) 4) public class WonderDraw 5) { 6) public static void main(string[] args) 7) { 8) Picture bob = new Picture(301, 301); 9) Graphics canvas = bob.getoffscreengraphics(); 10) canvas.setcolor(color.red); 11) for (int a=30; a<300; a=a+30) 1 13) //drawline(x1, y1, x2, y2) 14) canvas.drawline(a, a-10, a, a+10); 15) canvas.drawline(a, a, a+10, a+10); 16) canvas.drawline(a, a, a-10, a+10); 17) } 18) bob.repaint(); 19) } 20) } - 9 of 10 -

10) This Java program compiles and runs. What is the output? 1) import java.awt.graphics; 2) import java.awt.color; 3) 4) public class WonderDraw 5) { 6) public static void main(string[] args) 7) { 8) Picture bob = new Picture(401, 401); 9) Graphics canvas = bob.getoffscreengraphics(); 10) canvas.setcolor(color.green); 11) 12) for (int col = 0; col<4; col++) 13) { 14) for (int row = 0; row<4; row++) 15) { 16) if ((row == 2) (col == 3)) 17) { 18) int x = col*100; 19) int y = row*100; 20) canvas.fillrect(x, y, 95, 95); 21) } 22) } 23) } 24) bob.repaint(); 25) } 26) } - 10 of 10 -