English

Answer the following in brief. Give a reason/example wherever applicable. Give a program example of a method call in a loop.

Advertisements
Advertisements

Question

Answer the following in brief. Give a reason/example wherever applicable.

Give a program example of a method call in a loop.

Give Reasons
Advertisements

Solution

Example of a method call in a loop:

class Example 
{
    static void display()         
        {
        System.out.println("Hello Java");
    }

    public static void main(String[]args) 
        {
        for(int i=1; i<=5; i++) 
        {
            display();//Method call inside loop
        }
    }
}

Reason: The method display() is called repeatedly inside the for loop, so the same method executes multiple times with each iteration.

shaalaa.com
  Is there an error in this question or solution?
Chapter 3: User-Defined Methods - Exercises [Page 91]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 3 User-Defined Methods
Exercises | Q 5. (vi) | Page 91
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×