DOC PREVIEW
USF CS 110 - Repetition

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9RepetitionTypes of Loops•Counting loop–Know how many times to loop•Sentinel-controlled loop–Expect specific input value to end loop•Endfile-controlled loop–End of data file is end of loop•Input validation loop–Valid input ends loop•General conditional loop–Repeat until condition is metwhilewhile(condition){statements}whileint i = 0; //initialization of control variablewhile(i < end_value) //condition{System.out.println(“Number “ + i);i++; //update – DO NOT FORGET THIS!}for for(int i = 0; i < end_value; i++) {System.out.println(“Number “ + i);}Sentinel-controlledimport java.util.Scanner;public class Loops { public static void main(String[] args) {int input;Scanner s = new Scanner(System.in);System.out.println("Enter number - 0 to quit: ");input = s.nextInt();while(input != 0) { System.out.println("Your number is " + input); System.out.println("Enter number - 0 to quit: "); input = s.nextInt();} }}Input Validationimport java.util.Scanner;public class Loops { public static void main(String[] args) {int input;Scanner s = new Scanner(System.in);System.out.println("Enter number - 0 to 100: ");input = s.nextInt();while(input < 0 || input > 100) { System.out.println("Your number is out of range"); System.out.println("Enter number - 0 to 100: "); input = s.nextInt();} }}do-whileimport java.util.Scanner;public class Loops { public static void main(String[] args) {int input;Scanner s = new Scanner(System.in);do { //loop will always execute at least once! System.out.println("Enter number - 0 to 100: "); input = s.nextInt();} while(input < 0 || input > 100); }}Exercises1. Ex5.14 – Write a while loop that verifies that the user enters a positive integer value.2. Ex5.15 – Write a do loop that verifies the user enters an even integer value.3. Ex5.17 – Write a for loop to print the multiples of 3 from 300 down to 3.4. PP5.15 – Design and implement an application that reads a string from the user, then determines and prints how many of each lower-case vowel (a, e, i, o, u) appear in the entire string. Have a separate counter for each vowel. Also count and print the number of nonvowel


View Full Document

USF CS 110 - Repetition

Download Repetition
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Repetition and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Repetition 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?