Week4 - Weeks 4 and 5 (notes for chapters 4 and 5) if...

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

View Full Document Right Arrow Icon
Weeks 4 and 5 (notes for chapters 4 and 5)
Background image of page 1

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

View Full DocumentRight Arrow Icon
if Statements if (boolean condition) statement 1; else statement 2; if (boolean condition) {multiple statements} else {multiple statements} if (boolean condition 1) if (boolean condition 2) if (boolean condition 3) statement 1; else statement 2; else statement 3; else statement 4; Relational Operators: = = ! = > < > = < = Logical Operators: && | | Write code fragment to assign into biggest the largest value of a, b, c.
Background image of page 2
How to Assign the largest value of a, b, and c into the variable biggest using the conditional expression operator biggest = (a>b) ? ((a>c) ? a : c) : ((b>c) ? b : c);
Background image of page 3

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

View Full DocumentRight Arrow Icon
while Statement while (condition) { body of the loop } // Demonstrate the while loop. class While { public static void main( String args[ ]) { int n = 10; while (n > 0) { System.out.println(“tick ” + n); n--; } System.out.println(“Lift Off!”); } } Output: tick 10 tick 9 tick 8 tick 7 tick 6 tick 5 tick 4 tick 3 tick 2 tick 1 Lift off!
Background image of page 4
// The target of a loop can be empty. class NoBody { public static void main(String args[ ]) { int i = 100, j = 200; // find midpoint between i and j while (++i < --j) ; // no body in this loop System.out.println(“Midpoint is ” + i); Output: Midpoint is 150
Background image of page 5

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

View Full DocumentRight Arrow Icon
do-while Statement do { // body of loop } while ( condition ); // Demonstrate the do-while loop. Class DoWhile {
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/12/2009 for the course CS 120 taught by Professor Robertdependahl during the Fall '09 term at Santa Barbara City.

Page1 / 15

Week4 - Weeks 4 and 5 (notes for chapters 4 and 5) if...

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

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