Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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 使用整数获取颜色_Java_Colors_Integer - Fatal编程技术网

Java 使用整数获取颜色

Java 使用整数获取颜色,java,colors,integer,Java,Colors,Integer,标题有点混乱,但我想给颜色方法添加一个整数。我的意思是,如果我有三种颜色,并希望通过for循环(如下所示)来遍历它们: color1=something; 颜色2=某物; 颜色3=某物; 对于(int i=1;i4是假的,所以它不会做任何事情。@Steve我的错误。我希望第一种颜色(color1)将用于循环的第一次执行,第二种颜色(color2)将用于循环的第一次执行在第二个循环中,为什么要在循环中迭代3次? // take these three colors for example Colo

标题有点混乱,但我想给颜色方法添加一个整数。我的意思是,如果我有三种颜色,并希望通过for循环(如下所示)来遍历它们:

color1=something;
颜色2=某物;
颜色3=某物;
对于(int i=1;i<4;i++){
int r=color(i).getRed();
int g=color(i).getGreen();
intb=color(i).getBlue();
}

您可以将这三种颜色存储在一个数组中,并在循环中访问该数组

// take these three colors for example
Color[] colors = {Color.BLACK, Color.WHITE, Color.YELLOW};

for (int i=0; i<3; i++) {
    int r = colors[i].getRed();
    int g = colors[i].getGreen();
    int b = colors[i].getBlue();
}
//以这三种颜色为例
Color[]colors={Color.BLACK,Color.WHITE,Color.YELLOW};

对于(int i=0;我不理解你的问题…但是你的循环看起来确实很奇怪。因为在第一次迭代中1>4是假的,所以它不会做任何事情。@Steve我的错误。我希望第一种颜色(color1)将用于循环的第一次执行,第二种颜色(color2)将用于循环的第一次执行在第二个循环中,为什么要在循环中迭代3次?
// take these three colors for example
Color[] colors = {Color.BLACK, Color.WHITE, Color.YELLOW};

for (int i=0; i<3; i++) {
    int r = colors[i].getRed();
    int g = colors[i].getGreen();
    int b = colors[i].getBlue();
}