Intro to Java Web-Notes_Part27

Intro to Java Web-Notes_Part27 - int count = 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int count = 1; while (count <= 10) System.out.println("A"); count++; If we want to print the two lines A B ten times, does the following code accomplish this? int count : 1; while (count <: 10) System.out.println("A"); System.out.println("B"); If not, what needs to be changed? Here is another loop that is not quite right -- what is the problem with this loop? int count : 1; while (count <: 10) { System.out.println("A"); System.out.println("B"); count : ll; Exercises 1. What is the output of the following code? int index : 3; while (index <= 5) { System.out.println("indexz " + index); index++; l 2. What is the output of the following code? int num : 2; while (num < 5) num++; System.out.println("num: " + num); 3. What is the output of the following code? int num = 9; while (num < 5) num++; System.out.println("num: " + num); 4. What is the output of the following code? int x = 20; while (true) { System.out.println("A"); X++; } System.out.println("x is: " + x); 5. What is the output of the following code? int num : 2; while (num > O) { System.out.println("num: " + num); num——; l 6. What is the output of the following code? int num : 3; while (num — 5 < O) { System.out.println("num: " + num); num++; l More Loops With Problems Each of the loops in this section have some kind of problem. Follow the code and identify the problem. Also show the output of the code. Note that some of the problems below are related to the fact that Java considers an extra semicolon to be a complete "empty" statement. For example, the main method, below, contains four statements (two calls to the println method and two empty statements): public class Verifylt i public static void main(String args) { System.out.print;n("Hello"); I System.out.print;n("There"); } The empty statements are not as obvious when they are tacked onto the end of a non-empty statement. The program below is the exact same program as above, except the empty statements are placed at the end of the println statements: public class Verifylt i public static void main(String args) i System.out.println("Hello");; System.out.println("There");; 1. What is the output of the following code? int num : 10; while (num < 10) { System.out.println("numz " + num); num++; l System.out.println("donez " + num); ...
View Full Document

This note was uploaded on 11/17/2010 for the course CIS 1500 taught by Professor Staff during the Summer '08 term at Oakland CC.

Page1 / 2

Intro to Java Web-Notes_Part27 - int count = 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online