Question
10. What is wrong with the following for loop? What is the output after it is fixed? for (int k =1, k == 20; k++)
10. What is wrong with the following for loop? What is the output after it is fixed?
for (int k =1, k == 20; k++) {}
Your brief answer:
// 11. What does this do-while loop print (its OK as-is)?
int k = 3;
do
{
System.out.print(k);
} while (k != 3);
Your brief answer:
// 12. What is wrong with the following do-while loop? What is the output after it is fixed?
do
{
System.out.println("This looks correct")
} while {true};
Your brief answer:
// 13. assume String s = "0123456789"; how would you write a for-each loop that prints the characters in s, but only those that represent even numbers? A String for-each loop looks like this: for (char c : s.toCharArray()) { } // puts each character from s, one at a time, into variable c
// then you can use the char variable c inside the curly braces and only print the even ones
Your answer below copy the for-each loop and add your statements inside its curly braces:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started