Algorithm Sample - Listing the first 10 even numbers which are greater than 0


package algorithmsample28;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Nurhak
 */
public class AlgorithmSample28 {

    public static void main(String[] args) {
        int i = 0;
        ArrayList list = new ArrayList();
        do {
            if (i % 2 == 0) {
                System.out.println(i);
                list.add(i);
            }
            i++;
        } while (list.size() < 10);
     
        System.out.println("List of elements: ");
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Object object = it.next();
            System.out.println(object);
        }
    }
}

Comments

Popular posts from this blog

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"

Solution for "Can not obtain Oracle client information from registry"