computer

profilecara cao
CIS36A-Lab03-ControlStatements2.docx

CIS 36A :: LAB 3 - Control Statements

Student Name:

Instructions:

Make a copy of assignment template. Go to File => Make a copy (or download as a Word file.)

Complete definitions and attach Snipping Photos where appropriate

Place your name in the Title of each Assignment

For Example: CIS 36A- Assignment 1 - Basic Concepts - Irfan O.

Use the book or do online research to find answers.

Write your answers using a different font color. Find your own unique color.

Write answers in your own words. DO NOT COPY & PASTE from anywhere.

Submission: When done, go to File -> Download as -> Microsoft Word and then upload the file to Canvas.

Task 1: Definitions & Concepts

Instructions: Answer the questions below.

Keywords: To you best knowledge, describe below words:

System.in =>

Break =>

While =>

List Java’s selection statements: =>

What is a definite loop? =>

What is an infinite loop? How would you break one? =>

What is the difference between for loop and while loop? =>

When is a good time to use a do-while loop instead of a while loop? =>

Explain the difference between a using a break and a continue in a loop? =>

Task 2: Understanding Programming

Instructions: Answer each question below. Try to understand and explain the code. Do not put an IDE code screenshot.

Show the general if - else if - else ladder. =>

What is the difference between 5, ‘5’,”5”? =>

Given if(x < y) if(y > 100) { if(!done) x = z; else y = z; } else System.out.println("error"); // what if? To what if does the last else associate? =>

Show the for statement for a loop that counts from 2000 to 100 by -4. =>

Is the following fragment valid? Why or why not? for(int i = 0; i < num; i++) sum += i; count = i; =>

What does the following fragment print? for(int i = 0; i < 10; i++) { System.out.print(i + " "); if(i%2 == 0) continue; System.out.println(); } =>

Task 3: Programming Exercises

Instructions: Use any IDE to write and execute below exercises from the book chapter 3. Attach Snipping photos of your source code and execution of the code in the console. Make sure to create separate files for each exercise. Sample screenshot:

Chapter Examples: Follow the lectures to do below programs with the instructor.

Day 1: Kbln, Guess, Guess2, Compare, Compare2, Compares3, Ladder, SwitchDemo, GPACalculator, SqrRoot (Attached the screenshot of at least 3).

Day 2: DecrFor, MultipleLoopVars, ForTest, Empty, Empty2, ForVar, WhileDemo, Power, DWDemoe, Guess4, BreakDemo, Break2, Break3, ContDemo, FindFact, NestedDemo1, NestedDEmo2, NestedDemo3 (Attached the screenshot of at least 3).

Write one self-created loop example program.

TRY THIS

TRY THIS 3-1 - Page 87 - Do not submit this

TRY THIS 3-2 - Page 99 - Do not submit this

TRY THIS 3-3 - Page 110 - Only Submit output of this version

Chapter Exercises: Do the following chapter exercises.

Exercise 1: Write a program that reads characters from the keyboard until a ‘Q’ is received. Have the program count the number of ‘A’s. Report the total at the end of the program.

Exercise 15:

Exercise 16:

Exercise 17:

Exercise 18:

Exercise 20:

Extra Credit:

Exercise 19:

Exercise 21:

Exercise 22: