Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 不';while中逻辑and(&;)的t工作谓词 public void ReadPixels(字符串路径,FormController表单){ 图像=新图像(路径); PixelReader=image.getPixelReader(); int x=0; int y=0; int-stopX=0; int-stopY=0; 而(x!=form.canvas.getWidth()-1&&y!=form.canvas.getHeight()-1){ 而(x24)&0xFF; int g=(argb>>8)&0xFF; int b=argb&0xFF; 像素=新像素(r、g、b); 像素[][]阵列=新像素[20][25]; 矩阵=新矩阵(); 阵列[x][y]=像素; 矩阵。集合数组(数组); 如果(x!=stopX+20-1){ x++; } 如果(y!=stopY+25-1){ y++; } } x++; y++; stopX=x; stopY=y; } }_Java_Loops_While Loop - Fatal编程技术网

Java 不';while中逻辑and(&;)的t工作谓词 public void ReadPixels(字符串路径,FormController表单){ 图像=新图像(路径); PixelReader=image.getPixelReader(); int x=0; int y=0; int-stopX=0; int-stopY=0; 而(x!=form.canvas.getWidth()-1&&y!=form.canvas.getHeight()-1){ 而(x24)&0xFF; int g=(argb>>8)&0xFF; int b=argb&0xFF; 像素=新像素(r、g、b); 像素[][]阵列=新像素[20][25]; 矩阵=新矩阵(); 阵列[x][y]=像素; 矩阵。集合数组(数组); 如果(x!=stopX+20-1){ x++; } 如果(y!=stopY+25-1){ y++; } } x++; y++; stopX=x; stopY=y; } }

Java 不';while中逻辑and(&;)的t工作谓词 public void ReadPixels(字符串路径,FormController表单){ 图像=新图像(路径); PixelReader=image.getPixelReader(); int x=0; int y=0; int-stopX=0; int-stopY=0; 而(x!=form.canvas.getWidth()-1&&y!=form.canvas.getHeight()-1){ 而(x24)&0xFF; int g=(argb>>8)&0xFF; int b=argb&0xFF; 像素=新像素(r、g、b); 像素[][]阵列=新像素[20][25]; 矩阵=新矩阵(); 阵列[x][y]=像素; 矩阵。集合数组(数组); 如果(x!=stopX+20-1){ x++; } 如果(y!=stopY+25-1){ y++; } } x++; y++; stopX=x; stopY=y; } },java,loops,while-loop,Java,Loops,While Loop,我有个问题。在while循环中,当x增加到19时,while将退出其块。为什么 在while中,逻辑AND&。这意味着当表达式的第一部分和第二部分为FALSE时,循环将结束 在while中,逻辑AND&。这意味着当表达式的第一部分和第二部分为FALSE时,循环将结束 不,你倒过来了。当两个条件都为真时,循环将继续,即当违反任何条件时,循环将停止 在您的情况下,x为19,条件x

我有个问题。在while循环中,当
x
增加到19时,while将退出其块。为什么

在while中,逻辑AND&。这意味着当表达式的第一部分和第二部分为FALSE时,循环将结束

在while中,逻辑AND&。这意味着当表达式的第一部分和第二部分为FALSE时,循环将结束

不,你倒过来了。当两个条件都为真时,循环将继续,即当违反任何条件时,循环将停止

在您的情况下,
x
19
,条件
x
false
(其中
stopX
0
),因此内部循环停止


如果要在两个条件都为false时停止循环,请尝试将条件更改为
(x

第一次通过内部循环时,
stopX
0
,因此当
x
(和
y
)时退出内部循环是19。然后设置
stopX=x
,因此
stopX
现在是
19

因此,第二次通过内部循环时,
x
上的条件是
x<19+20-1
,即循环将持续到
x=38
。当
x
达到
20
时,您会得到一个
ArrayIndexOutOfBoundsException
访问
array[x][y]
,您应该(始终)使用编程语言添加标记。
public void ReadPixels(String path, FormController form){
    Image image = new Image(path);
    PixelReader reader = image.getPixelReader();
    int x = 0;
    int y = 0;
    int stopX = 0;
    int stopY = 0;
    while(x != form.canvas.getWidth()-1 && y != form.canvas.getHeight()-1){
        while(x < stopX+20-1 && y < stopY+25-1){
            int argb = reader.getArgb(x, y);
            int r = (argb >> 24) & 0xFF;
            int g = (argb >>  8) & 0xFF;
            int b =  argb        & 0xFF;
            Pixels pixel = new Pixels(r,g,b);
            Pixels[][] array = new Pixels[20][25];
            Matrix matrix = new Matrix();
            array[x][y] = pixel;
            matrix.setArray(array);
            if(x != stopX+20-1){
                x++;
            }
            if(y != stopY+25-1){
                y++;
            }

        }
        x++;
        y++;
        stopX=x;
        stopY=y;
    }
}