添加颜色并在rgb中发布

时间:2014-09-24 02:39:58

标签: java rgb

我试图从一种颜色变为红色,从另一种颜色变为绿色,从另一种颜色变为蓝色并添加它们以制作全新的颜色。但它一直说不能找到第2行符号,现在它说我需要一个返回类型。我该怎么办?

 public static four (String[] args) {
       Color colour4 = new Color();
       int red = colour1.getRed();
       int green = colour2.getGreen();
       int blue = colour3.getBlue();


       System.out.println("The RGB is: ("+red+","+green+","+blue+")");
}

其他颜色的代码通常是这个

public static void second (String[] args) {
      Scanner b = new Scanner (System.in);

      System.out.println("What's the decimal?");
      int value = b.nextInt();
      System.out.println("Your decimal is"+value);

      Color colour2 = new Color(value);
      int red = colour2.getRed();
      int green = colour2.getGreen();
      int blue = colour2.getBlue();

      System.out.println("The RGB is: ("+red+","+green+","+blue+")");
}

1 个答案:

答案 0 :(得分:0)

您的代码完全错误:

  • 应执行的方法始终命名为main,并且应为void(您未指定返回类型)。
  • 您的编译器遇到问题的原因是因为您使用了一个您尚未声明的变量(colour1
  • 颜色实际上没有"十进制"。红色通道是24位整数的8位,绿色通道是中间的8位,蓝色通道是8位最低位。

可能的解决方案:

public static void main (String[] args) {
    Scanner b = new Scanner (System.in);

    System.out.println("What's the first color decimal?");
    int value = b.nextInt();
    Color colour1 = new Color(value);

    System.out.println("What's the second color decimal?");
    value = b.nextInt();
    Color colour2 = new Color(value);

    System.out.println("What's the third color decimal?");
    value = b.nextInt();
    Color colour3 = new Color(value);

    int red = colour1.getRed();
    int green = colour2.getGreen();
    int blue = colour3.getBlue();

    Color colour4 = new Color(red,green,blue);

    //do something with colour4

    System.out.println("The RGB is: ("+red+","+green+","+blue+")"); 
}