Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CMYKtoRGB {
- public static void main(String[] args) {
- // Take 4 color values from command line argument.
- // these numbers will be real numbers from 0.0 to 1.o
- // use the double data type
- // cyan, magenta, yellow, and black will be the order they're inputed
- double cyan = Double.parseDouble(args[0]);
- double magenta = Double.parseDouble(args[1]);
- double yellow = Double.parseDouble(args[2]);
- double black = Double.parseDouble(args[3]);
- // convert these values to the RGB format
- double white = 1 - black;
- double red = 255 * white * (1 - cyan);
- double green = 255 * white * (1 - magenta);
- double blue = 255 * white * (1 - yellow);
- // now round these values to the nearest integer
- double red1 = Math.round(red);
- double green1 = Math.round(green);
- double blue1 = Math.round(blue);
- int red2 = (int) red1;
- int green2 = (int) green1;
- int blue2 = (int) blue1;
- // now print out the values :)
- System.out.println("red = " + red2);
- System.out.println("green = " + green2);
- System.out.println("blue = " + blue2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement