✏️ Explanatory Question

Question:

A student had written the following method to display “Hello World” four times:

void displayMessage()
{
    System.out.println("Hello World");
    System.out.println("Hello World");
    System.out.println("Hello World");
    System.out.println("Hello World");
}

Later, the student modified the code using a loop:

void displayMessage()
{
    int i = 1;
    while(i <= 4)
    {
        System.out.println("Hello World");
        i++;
    }
}

Compare the above code snippets with respect to time complexity.

👁 17 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Answer not available right now.