loop++; System.out.println(loop);

Similar documents
Peer Instruction 1. Elementary Programming

5) (4 points) What is the value of the boolean variable equals after the following statement?

CS 163/164 Exam 2 Review

Full file at

Manipulating One-dimensional Arrays

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

Loops! Step- by- step. An Example while Loop. Flow of Control: Loops (Savitch, Chapter 4)

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

CS211 Spring 2005 Prelim 1 March 10, Solutions. Instructions

Question: Total Points: Score:

Array. Prepared By - Rifat Shahriyar

Name Section Number. CS210 Exam #1 *** TURN OFF ALL ELECTRONIC DEVICES *** Practice

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

CS 163/164 Exam 2 Review

CS 307 Midterm 1 Fall 2007

Chapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );

CS 101 Exam 1 Spring 200 Id Name

Chapter 4: Control structures. Repetition

AP CS Fall Semester Final

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

OBJECTIVE QUESTIONS: Choose the correct alternative:

Chapter 4: Control structures

CS4215 Programming Language Implementation

that initializes the person s name from the input string. Consider the following fragment of Java code (inside some main method):

Introduction to Computer Science Midterm 3 Fall, Points

Outline of Fortran 90 Topics

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

NATIONAL UNIVERSITY OF SINGAPORE

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

CS Exam 2 Study Guide and Practice Exam

Java: Comment Text. Introduction. Concepts

Advanced if/else & Cumulative Sum

CS159. Nathan Sprague. September 11, 2015

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

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

AMCAT Procedure functions and scope Sample Questions

Simple Java Reference

CS 106 Introduction to Computer Science I

Declaring a 2D Array

CSIS 10A PRACTICE FINAL EXAM Name Closed Book Closed Computer 3 Sheets of Notes Allowed

Supplementary Test 1

Recursion. What is Recursion? Simple Example. Repeatedly Reduce the Problem Into Smaller Problems to Solve the Big Problem

Fall 2017 CISC124 9/16/2017

Introduction to Java Programming

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

Pull Lecture Materials and Open PollEv. Poll Everywhere: pollev.com/comp110. Lecture 12. else-if and while loops. Once in a while

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

1 Truth. 2 Conditional Statements. Expressions That Can Evaluate to Boolean Values. Williams College Lecture 4 Brent Heeringa, Bill Jannen

Control Statements Loops

Prelim 1. CS 2110, 13 March 2018, 7:30 PM Total Question Name Short answer

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

AP CS Unit 7: Arrays Exercises

Getting started with Java

CS 101 Spring 2007 Midterm 2 Name: ID:

Introduction to Java

CS 307 Midterm 1[corrected] Spring 2008

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

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

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

CS302: Self Check Quiz 2

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

APCS Semester #1 Final Exam Practice Problems

Week 1: Hello World! Muhao Chen

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

CSEN 202 Introduction to Computer Programming

Full file at

CS201- Introduction to Programming Current Quizzes

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.5. for loop and do-while loop

CS 1331 Exam 1 ANSWER KEY

Computers, Variables and Types. Engineering 1D04, Teaching Session 2

CS 61B Data Structures and Programming Methodology. June David Sun

Hashing. 5/1/2006 Algorithm analysis and Design CS 007 BE CS 5th Semester 2

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

QUIZ: loops. Write a program that prints the integers from -7 to 15 (inclusive) using: for loop while loop do...while loop

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

Announcements. Project 1 will be posted today on webpage and cvs. Due Tuesday

Arrays in Java Multi-dimensional Arrays

Dept. of CSE, IIT KGP

Slide 1 Side Effects Duration: 00:00:53 Advance mode: Auto

CSE 1223: Exam II Autumn 2016

STRUCTURED DATA TYPE ARRAYS IN C++ ONE-DIMENSIONAL ARRAY TWO-DIMENSIONAL ARRAY

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

CS110: PROGRAMMING LANGUAGE I

Algebra 1 Semester 2 Final Review

String Computation Program

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

Lesson 35..Two-Dimensional Arrays

Java Control Statements

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

CS 100 Python commands, computing concepts, and algorithmic approaches for final Fall 2015

Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

Looping. Arizona State University 1

Object Oriented Programming 2013/14. Final Exam June 20, 2014

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz II

Transcription:

What value is printed for the loop variable when the code shown below runs? int loop = 0; while (loop <= 10) { loop++; System.out.println(loop); A. 0 to 9 B. 0 to 10 C. 1 to 10 D. 1 to 11 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 1

What value is printed for the loop variable when the code shown below runs? int loop = 0; while (loop <= 10) { loop++; System.out.println(loop); A. 0 to 9 B. 0 to 10 C. 1 to 10 D. 1 to 11 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 2

What value is printed for the loop variable when the code shown below runs? int loop =0; while (loop <= 10) { loop++; System.out.println(loop); A. 9 B. 10 C. 11 D. 12 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 3

What value is printed for the loop variable when the code shown below runs? int loop =0; while (loop <= 10) { loop++; System.out.println(loop); A. 9 B. 10 C. 11 D. 12 E. Will not compile! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 4

How many times will the body of the do while loop execute? byte loop = -1; do { loop++; while (loop < 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 5

How many times will the body of the do while loop execute? byte loop = -1; do { loop++; while (loop < 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Question - 6

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many times will the body of the do while loop execute? byte loop = 0; do { loop++; while (loop > 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! Questi on - 7

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many times will the body of the do while loop execute? byte loop = 0; do { loop++; while (loop > 0); A. 0 times B. 1 time C. 2 times D. 128 times E. Infinite loop! Questi on - 8

cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What will the code shown below print to the console? System.out.println( Character.isDigit( A ) + "," + Character.isLetter( z ) + "," + Character.isLowerCase( & ) + "," + Character.isLetter("5A%".charAt(1)); A. true,false,true,false B. false,true,false,true C. false,true,false,false D. false,true,true,true Questi on - 9

cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What will the code shown below print to the console? System.out.println( Character.isDigit( A ) + "," + Character.isLetter( z ) + "," + Character.isLowerCase( & ) + "," + Character.isLetter("5A%".charAt(1)); A. true,false,true,false B. false,true,false,true C. false,true,false,false D. false,true,true,true Questio n - 10

cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What are the values of the double and integer after the code shown below executes? String mystring = "1.234"; double mydouble = Double.parseDouble(myString); int myinteger = Integer.parseInt(myString); A. 1.234, 0 B. 1.234, 1 C. 1.234, 2 D. Program gets an exception! Questio n - 11

cs163/164: Peer 3 - Math/Characters/Strings - Fall Semester 2016 What are the values of the double and integer after the code shown below executes? String mystring = "1.234"; double mydouble = Double.parseDouble(myString); int myinteger = Integer.parseInt(myString); A. 1.234, 0 B. 1.234, 1 C. 1.234, 2 D. Program gets an exception! Questio n - 12

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many lines does the nested loop shown below print? for (int row = 0; row < 10; row += 2) { for (int col = 0; col < 50; col += 10) { System.out.println(row + "," + col) ; A. 20 times B. 25 times C. 36 times D. 500 times E. Different each time it runs! Questio n - 13

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 How many lines does the nested loop shown below print? for (int row = 0; row < 10; row += 2) { for (int col = 0; col < 50; col += 10) { System.out.println(row + "," + col) ; A. 20 times B. 25 times C. 36 times D. 500 times E. Different each time it runs! Questio n - 14

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Which of the following correctly prints the entire contents of the string? String s = "Programming is fun!"; A. for (int i=1; i< s.length(); i++) System.out.print(s.charAt(i)); B. for (int i=1; i<= s.length(); ++i) System.out.print(s.charAt(i)); C. for (int i=0; i<= s.length(); i++) System.out.print(s.charAt(i)); D. for (int i=0; i< s.length(); ++i) System.out.print(s.charAt(i)); Questio n - 15

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 Which of the following correctly prints the entire contents of the string? String s = "Programming is fun!"; A. for (int i=1; i< s.length(); i++) System.out.print(s.charAt(i)); B. for (int i=1; i<= s.length(); ++i) System.out.print(s.charAt(i)); C. for (int i=0; i<= s.length(); i++) System.out.print(s.charAt(i)); D. for (int i=0; i< s.length(); ++i) System.out.print(s.charAt(i)); Questio n - 16

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 What is the last thing printed by the for loop shown below? for (String s = "Hello"; s.length() <= 10; s += "!") { System.out.println(s); A. Hello B. Hello! C. Hello!!!!! D.!!!!! E. None of the above Questio n - 17

cs163/164: Peer 4 - Control Loops - Fall Semester 2016 What is the last thing printed by the for loop shown below? for (String s = "Hello"; s.length() <= 10; s += "!") { System.out.println(s); A. Hello B. Hello! C. Hello!!!!! D.!!!!! E. None of the above Questio n - 18