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

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

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

Building Java Programs

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

Building Java Programs

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

Chapter 6 Single-dimensional Arrays

( &% class MyClass { }

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

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

Java Simple Data Types

Computational Expression

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

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

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

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

Administration. Objects and Arrays. Objects. Agenda. What is an Object? What is a Class?

PROGRAMMING FUNDAMENTALS

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

AP CS Unit 3: Control Structures Notes

Selected Questions from by Nageshwara Rao

Building Java Programs

Key Java Simple Data Types

Arrays in Java Using Arrays

Java Identifiers, Data Types & Variables

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Controls Structure for Repetition

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.

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Final Exam Practice. Partial credit will be awarded.

Introduction to Java

CS111: PROGRAMMING LANGUAGE II

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

CS170 Introduction to Computer Science Midterm 2

Building Java Programs

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

Java Simple Data Types

JAVA OPERATORS GENERAL

CT 229 Methods Continued

Introduction to Computer Science Unit 2. Notes

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

Getting started with Java

CSE 142, Summer 2014

Oct Decision Structures cont d

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

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

AP Computer Science Unit 1. Programs

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

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

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

Array. Array Declaration:

Fundamentals of Programming Data Types & Methods

Introduction to Programming (Java) 4/12

CSC 1214: Object-Oriented Programming

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

Review Ch 5 static Multiple Choice Test Creating Class Methods

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

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.

CP122 CS I. Iteration

An overview of Java, Data types and variables

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

Handout 4 Conditionals. Boolean Expressions.

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

CSE 142, Summer 2015

Computer Science is...

Supplementary Test 1

- Thus there is a String class (a large class)

CS 139 Practice Midterm Questions #2

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

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

Java Basic Programming Constructs

Introduction to Computer Science Unit 2. Notes

Computational Expression

Assignment 1 due Monday at 11:59pm

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

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

Lec 7. for loops and methods

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)

Class Libraries and Packages

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Question: Total Points: Score:

More on Classes. 1 tostring

1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean

H212 Introduction to Software Systems Honors

Lecture 5: Methods CS2301

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

CS 106 Introduction to Computer Science I

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

Chapter 5: Methods. by Tony Gaddis. Starting Out with Java: From Control Structures through Objects. Fourth Edition

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

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

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

Lecture Set 4: More About Methods and More About Operators

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

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

Building Java Programs. Introduction to Programming and Simple Java Programs

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

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.

Intro to Programming in Java Practice Midterm

Transcription:

Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between internal and external storage. data structure with one, or more, elements, called fields, of the same or different data types. 02. Consider the following program segment. int[] list; list = new int[100]; How many integers can be stored in the list array (A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution 03. Consider the two program segments below. Segment1 int list[ ]; list = new int[100]; Segment2 int list[ ] = new int[100]; Which of the following is a true statement about the comparison of Segment1 and Segment2? (A) (B) (C) (D) Segment1 declares list correctly. Segment2 declares list incorrectly. Segment1 declares list incorrectly. Segment2 declares list correctly. Both Segment1 and Segment2 declare list correctly. Both Segment1 and Segment2 declare list incorrectly. 04. Consider the program segment below. double[] grades; grades = new double[50]; What is the index range capable of accessing an element of the grades array? (A) 0..49 (B) 1..49 (C) 0..50 (D) 1..50

05. What is the output of program Java1012.java below? public class Java1012 public static void main(string[] args) int list[ ]; list = new int[10]; for (int k = 0; k < 10; k++) list[k] = 0; for (int k = 0; k < 10; k++) System.out.print(list[k] + " "); System.out.println(); (A) 0 0 0 0 0 0 0 0 0 0 (B) 0 1 2 3 4 5 6 7 8 9 (C) 1 2 3 4 5 6 7 8 9 10 (D) 0 0 0 0 0 0 0 0 0 06. What is the output of program Java1013.java below? public class Java1013 char[] list = new char[5]; for (int k = 0; k < list.length(); k++) list[k] = 'Q'; for (int k = 0; k < 5; k++) System.out.print(list[k] + " "); System.out.println(); (A) QQQQQQ (B) Q R S T U (C) Q Q Q Q Q (D) QQQQQ (E) ERROR

07. What is the output of program Java1014.java below? public class Java1014 int list[ ] = 1,2,3,4,5; for (int k = 1; k < list.length; k++) System.out.println("list[" + k + "] = " + list[k]); (A) list[0] = 0 list[1] = 1 (B) list[0] = 1 list[1] = 2 (C) list[1] = 1 list[5] = 5 (D) list[1] = 2 (E) Compile Error

08. What is the output of program Java1015.java below? public class Java1015 int list[ ] = 1,2,3,4,5; for (int k = 1; k <= 5; k++) System.out.println("list[" + k + "] = " + list[k]); (A) list[0] = 0 list[1] = 1 (B) list[0] = 1 list[1] = 2 (C) list[1] = 1 list[5] = 5 (D) list[1] = 2 (E) Array Out of Bounds Exception Error

09. What is the output of program Java1016.java below? public class Java1016 int[] list = 1,2,3,4,5; for (int k = list.length-1; k > = 0; k--) System.out.println("list[" + k + "] = " + list[k]); (A) list[1] = 2 list[0] = 1 (B) list[5] = 5 list[1] = 1 (C) list[5] = 4 list[4] = 3 list[3] = 2 list[2] = 1 list[1] = 0 (D) list[4] = 1 list[3] = 2 list[1] = 4 (E) Compile Error

10. What is the FIRST and LAST output from this program segment? int[] IntNum = new int[100]; for (J=0; J<100; J++) IntNum[J] = J; for (J=0; J<100; J++) System.out.println(IntNum[J]); (A) 0 and 100 (B) 0 and 99 (C) 1 and 100 (D) 1 and 99 11. What is the FIRST and LAST output from this program segment? int IntNum[] = new int[100]; for (J=1; J<=100; J++) IntNum[J] = J; for (J=1; J<=100; J++) System.out.println(IntNum[J]); (A) 0 and 100 (B) 0 and 99 (C) 1 and 100 (D) 1 and 99 12. What is the FIRST and LAST output from this program segment? int IntNum[] = new int[100]; for (J=0; J<100; J++) IntNum[J] = 100-J; for (J=85; J>=15; J--) System.out.println(IntNum[J]); (A) FIRST: 0 LAST: 99 (B) FIRST: 99 LAST: 0 (C) FIRST: 15 LAST: 85 (D) FIRST: 85 LAST: 15 13. What is the output from this program segment? int[] IntNum = new int[10]; for (J=0; J<10; J++) if (J < 2) IntNum[J] = J; else IntNum[J] = IntNum[J-1] + IntNum[J-2]; for (J=0; J<10; J++) System.out.print(IntNum[J] + " "); (A) 1 2 3 4 5 6 7 8 9 10 (B) 0 1 2 3 4 5 6 7 8 9 (C) 1 1 2 3 5 8 13 21 34 55 (D) 0 1 1 2 3 5 8 13 21 34 (E) 0 1 1 2 3 5 8 13 21 34 55

Objective 4 Initialized Arrays and length Use this program segment to answer questions 14-17. Boolean[] George = new boolean[15]; System.out.println(George.length); // Question #21 for (J=0; J<15; J++) if (J == 0) George [J] = (J==0); else George [J] =!George[J-1]; System.out.println(George[7]); // Question #22 System.out.println(George[8]); // Question #23 System.out.println(George[15]); // Question #24 14. What is the output of the first println? 15. What is the output of the second println? 16. What is the output of the third println? 17. What is the output of the fourth println?