Skip to content

Instantly share code, notes, and snippets.

@nbavafa
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbavafa/c70c33532a63ee4f4b3f to your computer and use it in GitHub Desktop.
Save nbavafa/c70c33532a63ee4f4b3f to your computer and use it in GitHub Desktop.
ProblemSet6
-------------------------------------------------------------------------------------------------------------------
Pset 6
1. What is an infinite loop?
An infinate loop is a loop that does not end and has no quit condititon
2. How do you prevent an infinite loop?
By having a condiditon in which the loop will end/quit.
2. Create a while loop which:
1. Checks to make sure that the user entered a positive number
while (num>0)
2. User enters a word with 5 characters
while (num.length() == 5)
3. User's entry begins with the letter c
char num = input.charAt(0);
String str = Character.toString(num);
if (str.equals("c"))
4. Checks to see that the user entered a valid input (valid input options are: 1, 2 or 3)
while ( x == 1 || x == 2 || x == 3)
5. Prints all multiples of 3 between 3 and 99 inclusive.
x = 3
while (x != 100)
System.out.println("x");
x++;
6. Given a word, it checks how many times the letter "e" appears in the word.
while (str.contains("e")) {
str = str.replace("e", "")'
i++;
System.out.println(i);
3. Multiple choice 3.7
B
4. Short answer 3.7
2, 4, 6, 8, 10, 12, 14, 16, 18, 20
5. Short answer 3.11
1) count--;
2) count = 0;
3) count = 0 && count--;
6. Short answer 3.13
System.out.println("Enter a number")
num = input.nextInt();
while (num>0) {
System.out.println("Enter a number")
num = input.nextInt();
@nbavafa
Copy link
Author

nbavafa commented Oct 6, 2014

Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment