




























































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!





























































A) Practice with Java Control Structures B) Methods Dr Olly Gotel [email protected] http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors
for (int count = 1; count <5; count++) System.out.println(“Num = ” + count);
Uh oh – the most common mistake! What is wrong with this? Hint – look at the initial values of max & min Also – try using a do-while loop import java.util.Scanner; next = scan.nextInt(); Scanner scan = new Scanner(System.in); next = scan.nextInt();
“This is a string”
int count, sum = 0; System.out.println(“Sum is ” + sum); for (count = 1; count < 10; count++){ sum = sum + count; System.out.println(“Count is ” + count); System.out.println(“Sum is ” + sum); } System.out.println(“Sum = ” + sum);
From [Savitch 2004] – ignore the old ways of reading input (superseded by Scanner in Java 5.0)
while (condition) { int x = 10; // can use x here } // can’t use x here
enclosing braces (i.e. ONLY exists and can be used inside here { here } )