UOP PRG420 Week 3 Discussion Latest

PRG420 Java Programming I
Week 3 Discussion
Loop Syntax
Research and discuss the following:
• Is the following code syntactically correct? How did you determine your answer?
If the following code is not syntactically correct, what is missing? If it is syntactically correct, what is the expected result?
for ( ; ; ) {
System.out.println("In the body of the loop");
}Many programmers use variables named i, j, or k to increment a loop counter, as shown below. However, variables can be named anything a programmer wants to name them, as long as they follow Java™'s syntactical rules for variable names. What are the benefits and drawbacks of using variable names such as i to increment or decrement loop counters vs. other variable names, such as counter or myCounter or hour?
for (int i = 1; i <= 24; i++) { // using i as counter
if (i < 12) { // morning hours
System.out.println(i + " a.m.");
}else if (i == 12) { // noon is a special case
System.out.println(i + " p.m.");
}else // afternoon hours {
System.out.println(i-12 + " p.m.");
}}Supporting Activity: Loops
Our focus this week is loops.
Select and complete one of the following activities:
Convert the following program from for loop to while loop.
class Arithmetic Progression
{ public static void main (String [] args)
{ int sum = 0;
while (int I != -1)
{ sum = sum + i;
System.out.println(Integer.toString(sum));
} }}Supporting Activity: Conditions
Consider the following conditions
CONDITION 1: while ( !(cChoice == 'Q' || cChoice == 'q') )
CONDITION 2: while ( cChoice != 'Q' || cChoice != 'q' )
Do Conditions 1 and 2 give the same result? What tool or technique would you use to explain the result?

-
Rating:
5/
Solution: UOP PRG420 Week 3 Discussion Latest