有没有办法在Java中进行n级嵌套循环? [英] Is there any way to do n-level nested loops in Java?

查看:113
本文介绍了有没有办法在Java中进行n级嵌套循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,我可以做一些像

$ p $ for(){
for {
对于{
}
}
}

除N次外?换句话说,当创建循环的方法被调用时,它被赋予了一些参数N,然后这个方法会创建N个这样的循环嵌套在一起吗?

当然,这个想法是应该有一个简单或通常的方式来做到这一点。我已经有了一个非常复杂的想法。

解决方案

这听起来像你可能想看看递归。


In other words, can I do something like

for() {
    for {
       for {
       }
    }
}

Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?

Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.

解决方案

It sounds like you may want to look into recursion.

这篇关于有没有办法在Java中进行n级嵌套循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆