{% highlight java %} /** * --------------------------------------------------------------------------- * File name: DoWhileLoopExercises.java * Project name: Winter Study Guide * --------------------------------------------------------------------------- * Author’s name and email: Michael Schneider, schneidm@etsu.edu * Course-Section: All * Creation Date: 1/5/15 * Last modified: Schneider 1/5/15 schneidm@etsu.edu * --------------------------------------------------------------------------- */ import java.util.Scanner; /** * Class Name: DoWhileLoopExercises
* Class Purpose: To give answers for the do...while loop exercises *
* *
* Date created: 1/5/15
* Last modified: Schneider 1/5/15 schneidm@etsu.edu * @author Michael Schneider */ public class DoWhileLoopExercises{ public static void main(String[] args){ /******************************************************* * * Examples * ********************************************************/ //Create a do...while loop that displays 0 to 15 to the screen int counter = 0;//Set initial state do//Conditional statement { System.out.println(" " + counter); counter++;//Update counter }while(counter <= 15); //Using a do...while loop, displays ("Please enter 4") until the user enters 4 Scanner kb = new Scanner(System.in); int input; do//Conditional Statement { System.out.println("Please enter 4"); input = kb.nextInt();//Update state }while(input != 4); /********************************** * * Counting Exercises * ***********************************/ //Problem 1 //Create a do...while loop that counts from 1 to 10 //Problem 2 //Create a do...while loop that counts from 0 to 50 by counting by 5 //Problem 3 //Create a while loop that counts from 10 to 1 /********************************** * * Repetitive Exercises * ***********************************/ //Problem 1 //Sum all the numbers from 1 to 50 //Problem 2 // Write the necessary code to do the following: // -Display the following menu to the user. // 1. Say "Hello" // 2. Say "Good Bye" // 3. Exit // // -Process the user's response // // -Display an error message if the user enters an invalid number // (i.e. a number not 1-3) // // -Keep asking the user for input until they enter 3 // } } {% endhighlight %}