Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements Exam 1 Thursday Everything through Lab 5 50 minutes

Similar presentations


Presentation on theme: "Announcements Exam 1 Thursday Everything through Lab 5 50 minutes"— Presentation transcript:

1 Announcements Exam 1 Thursday Everything through Lab 5 50 minutes
15 % of Total Grade Covers Everything through Lecture last Week General Topics (terminology, variables, constants, basics) if-then-else Compound statements Relational operators Equality operators and .equals() Logical operators Switch/Case Statements

2 Iteration Iteration (Looping): Performing a Series of Statements Multiple Times until Some Condition Is Met. Eliminates the Need for Redundant Coding or Function Calls Many Ways to Loop in JAVA

3 The while Loop Syntax: while (condition) statement; while (condition)
{ statement; }

4 while Example final int MAX = 100; int counter = 0;
while (counter < MAX) { System.out.println( counter + “ “ ); counter++; }

5 Example while Loop int numEmployees,curNum = 0;
System.out.print(“Enter Number of Employees: “); numEmployees = scan.nextInt(); if (numEmployees > 0) { while (curNum < numEmployees) System.out.println( “Welcome to CorpLand!” ); curNum++; }

6 The for Loop Syntax: Same as: for (expression1;condition; expression2)
statement; { } Same as: expression1; while (condition) expression2;

7 Example for Loop System.out.println( “Welcome to CorpLand!” ); }
int numEmployees,curNum; System.out.print(“Enter Number of Employees: “); numEmployees = scan.nextInt(); if (numEmployees > 0) { for (curNum = 0; curNum < numEmployees;curNum++) System.out.println( “Welcome to CorpLand!” ); }

8 Looping for Input char letterEntered = ‘A’; String stringE;
while (letterEntered != ‘Z’) { System.out.print(“Enter a letter: “); stringE = scan.next(); letterEntered = stringE.charAt(0); }

9 Looping until Flag boolean noMoreData(); boolean done = false; …
while (!done) { // do a bunch of stuff if (noMoreData() == true) done = true; } System.out.println(“ We’re all through – thank you!”);

10 Nested Loops int i , j ; for (i=0; i < 10; i++) {
for (j=0; j < 10; j++) System.out.print(i); System.out.print(j); System.out.print(“ “ ); } System.out.println();

11 The do-while Loop Syntax do statement; while (condition); { }

12 do-while Example char letterEntered; String stringE; do {
System.out.print(“Enter a letter: “); stringE = scan.next(); letterEntered = stringE.charAt(0); } while (letterEntered != ‘Z’);

13 What Is This? while (!stringEntered.equals(“apple”)) {
System.out.println( “Enter a red fruit: “); stringEntered = scan.next(); } while (!stringEntered.equals(“banana”)) System.out.println(“Enter a yellow fruit: “); while (!stringEntered.equals(“pomegranate”)) System.out.println(“Enter a random fruit: “);

14 What Is This? for (i = 0; i < 10 ; i++)
System.out.println( “Interesting, isn’t it?”); while (answer.charAt(0) != ‘D’) { System.out.print( “Enter an answer: “); answer = scan.next(); }

15 What Is This? void kingsChair(int loopCounter) { int num;
for(num = 0; num < loopCounter; num++) System.out.println(“AAAAAAAAAAAAAAAAAAAAAAAAAA”); }

16 Announcements Exam 1 Thursday Everything through Lab 5 50 minutes
15 % of Total Grade Covers Everything through Lecture last Week General Topics (terminology, variables, constants, basics) if-then-else Compound statements Relational operators Equality operators and .equals() Logical operators Switch/Case Statements


Download ppt "Announcements Exam 1 Thursday Everything through Lab 5 50 minutes"

Similar presentations


Ads by Google