

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Hanks; Class: Intro to Programming in Java; Subject: Computer Science Info Systems; University: Fort Lewis College; Term: Unknown 1989;
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Announcements Quiz – Monday, Oct. 3 Read: Chapter 4, sections 4.11 and 4.12 (pages 100 – 110) Last time : For loops for ( ForInit; ForExpression; ForUpdate ) Statement Draw flowchart, using above labels. Then redraw using below example. int value = 1; for ( int i = 0; i < 5; i++ ) { System.out.println( value ); value *= 2; } Another example: double money = 100; double interest = .05; int year; for ( year = 1; year <= 20; year++ ) { money *= 1 + interest; } S.O.PL("You have $"+ money + " after 20 years."); Remember, loop control variable does not have to increase, and it does not have to change its value by 1. for ( int count = 20; count > 0; count -= 7 ) { System.out.println( count ); } *Operators +=, -=, =, /=, %= In our programs, we frequently use a variable, add a value to it, and assign the result back into the original variable: valueSum = valueSum + value;
money = money * (1 + interest); This is a very common type of expression, so Java provides a shorthand operator for us valueSum += value; money = 1 + interest; // Also /=, -=, %= String s = ""; for ( int = 0; j < 20; j++ ) { s += ""; } Relationship between while loops and for loops. How can you convert one to the other? Look at the parts, show how they relate to each other What are the ‘rules’ for deciding whether to use a for loop or a while loop?