UOP PRG420 Week 3 Discussion Latest

Question # 00784871 Posted By: rey_writer Updated on: 11/25/2020 09:16 AM Due on: 11/25/2020
Subject Education Topic General Education Tutorials:
Question
Dot Image

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?

Dot Image
Tutorials for this Question
  1. Tutorial # 00784773 Posted By: rey_writer Posted on: 11/25/2020 09:17 AM
    Puchased By: 2
    Tutorial Preview
    The solution of UOP PRG420 Week 3 Discussion Latest...
    Attachments
    UOP_PRG420_Week_3_Discussion_Latest.ZIP (18.96 KB)

Great! We have found the solution of this question!

Whatsapp Lisa