小编Ant*_*nio的帖子

改变for循环的顺序?

我有一种情况,我需要根据用户输入循环不同顺序的xyz坐标.所以我是3D空间中的一个区域,然后是一组像这样的for循环.

for(int x = 0; x < build.getWidth(); x++){
   for(int y = 0; y < build.getHeight(); y++){
     for(int z = 0; z < build.getLength(); z++){
        //do stuff
       }
    }
 }
Run Code Online (Sandbox Code Playgroud)

但根据用户输入,订单可能是这样的.

for(int z = 0; z < build.getLenght(); z++){
   for(int y = 0; y < build.getHeight(); y++){
     for(int x = 0; x < build.getWidth(); x++){
        //do stuff
       }
    }
 }
Run Code Online (Sandbox Code Playgroud)

甚至是否定的.

for(int x = build.getWidth(); x > 0; x--){
   for(int y = 0; y < build.getHeight(); y++){
      for(int z = …
Run Code Online (Sandbox Code Playgroud)

java 3d loops dynamic coords

5
推荐指数
1
解决办法
593
查看次数

标签 统计

3d ×1

coords ×1

dynamic ×1

java ×1

loops ×1