Simulating nested loops

后端 未结 2 837
耶瑟儿~
耶瑟儿~ 2020-12-18 17:21

In a beginner\'s programming book (free licence) there was the following code, dynamically creating nested loops in Java:

import java.util.Scanner;

public c         


        
2条回答
  •  半阙折子戏
    2020-12-18 17:44

    It might be solved with this library, for example.

    In your case you can implement loops so:

    new Loops()
        .from(1).to(4)
        .from(1).to(4)
        .action(System.out::println);
    

    The result:

    [1, 1]
    [1, 2]
    [1, 3]
    [2, 1]
    [2, 2]
    [2, 3]
    [3, 1]
    [3, 2]
    [3, 3]
    

提交回复
热议问题