Question:

Java: How to add a loop inside a method?

by  |  earlier

0 LIKES UnLike

Is it really possible to add a for-loop inside a Java method? I have been trying this for hours but I keep on getting errors. Can you please give a simple java program that has a loop inside a method (without any swing or AWT)?

 Tags:

   Report

2 ANSWERS


  1. loops can be added inside a method ..

    declare a variable inside method and use it as a loop variable...


  2. public static void testMethod(){

    for(int k=0; k<10; k++){

    }

    }

    or

    public static int testMethod(){

    int x=0;

    for(int k=0; k<10;k++){

    x=k;

    }

    return x;

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions