















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















E.g., You may want to calculate the interest paid on a mortgage for each year of the loan term.
boolean_expression statement (body of loop) true false
boolean_expression statement (body of loop) true false
! int i = 0;! ! while (i < n) {! !! System.out.print(“”);! !!* i++;! ! }! ! System.out.println();!
// initialize // test // update
int i = 0;! while (i < n) {!! System.out.print(“”);! !* i++;! }! System.out.println();! For n = 5 the output is ***** (5 asterisks) ! int i = 1 ;! ! while (i < n) {! !! System.out.print (“”);! !!* i++;! ! }! ! System.out.println();! Output?
int i = 0;! while (i < n) {! !! System.out.print(“”);! !* i--;! }! System.out.println();!
int i = 0;! while (i < n) {! !! System.out.print(“”);! !* i--;! }! System.out.println();!
boolean_expression statement false true
Scanner keyboard = new Scanner(System.in);! System.out.print(! !! “Please enter the month [1-12]: ”);! int month = keyboard.nextInt();!
Scanner keyboard = new Scanner(System.in);! int month;! do {! ! System.out.print(! !! “Please enter the month [1-12]: ”);! ! month = keyboard.nextInt();! } while ( month < 1 || month > 12 );! Must be declared outside the loop Outside the scope of the loop