-
Notifications
You must be signed in to change notification settings - Fork 37
/
CmykToRgb.java
45 lines (37 loc) · 1.21 KB
/
CmykToRgb.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Task:
Given a color in CMYK format, output the corresponding RGB color.
Input Format:
4 decimal numbers in the range of [0, 1], representing Cyan, Magenta, Yellow and Black.
Output Format:
A string, representing the corresponding RGB color, each component separated by commas.
Sample Input:
0.4
0.49
0.552
0.36
Sample Output:
98,83,73
*/
import java.util.Scanner;
import static java.lang.Math.round;
/**
* @author Jegors Čemisovs
*
* {@url https://github.com/rabestro/sololearn-challenges}
*/
public final class CmykToRgb {
public static void main(final String[] args) {
final var scanner = new Scanner(System.in);
// I chose the float as the most suitable type
final var cyan = scanner.nextFloat();
final var magenta = scanner.nextFloat();
final var yellow = scanner.nextFloat();
final var black = scanner.nextFloat();
// round(float) returns int type, so we no need force conversion
final int red = round(255 * (1-cyan) * (1-black));
final int green = round(255 * (1-magenta) * (1-black));
final int blue = round(255 * (1-yellow) * (1-black));
System.out.printf("%d,%d,%d", red, green, blue);
}
}