Epic Systems Interview Question
Software DevelopersCountry: United States
Interview Type: Written Test
what is the meaning about the method of "switchrgb"? I don't understand that and could you explain in details. Thank you, albertchenyu!
Hi @teargone08 switchrgb is a switch function, what I want to do first is sortting the r, g ,b array. I'm using bubble sort method, so it requires switch in two adjacent element in an array. It's just a helper function for sortting.
public class RGBParser {
public static void parser (String rgb) {
if(rgb.length() != 6 ) {
System.out.println("Not a valid RBB string");
return;
}
int r = Integer.decode("0x"+rgb.substring(0, 2));
int g = Integer.decode("0x"+rgb.substring(2, 4));
int b = Integer.decode("0x"+rgb.substring(4, 6));
//Case 1: All three values are different. Print the bigger one
if(r != g && r != b && g != b) {
if(r > g && r > b) {
System.out.println("Red value is the biggest");
} else if (g > r && g > b) {
System.out.println("Green value is the biggest");
} else {
System.out.println("Blue value is the biggest");
}
} else if(r==g && r==b) { // Case 2. All three colours are equal
System.out.println("All three colours are equal");
} else { // Case 3. Two colours are equal
if (r==g) {
if(r > b) {
System.out.println("Red and green are equal and greater than Blue ");
} else {
System.out.println("Red and green are equal and lesser than Blue ");
}
}
else if(r==b) {
if(r > g) {
System.out.println("Red and blue are equal and greater than green ");
} else {
System.out.println("Red and blue are equal and lesser than green ");
}
}
else if (g==b) {
if(g > r) {
System.out.println("Blue and green are equal and greater than Red ");
} else {
System.out.println("Blue and green are equal and lesser than Red ");
}
}
}
}
public static void main(String[] args) {
String RGB = "F8FFFF";
parser(RGB);
}
}
public class P23 {
private static void compare(String first, String second) {
for (int i = 0; i < first.length(); i++) {
if (first.charAt(i) > second.charAt(i)) {
System.out.println("First is larger");
return;
} else if (first.charAt(i) < second.charAt(i)) {
System.out.println("Second is larger");
return;
}
}
System.out.println("Equal");
}
public static void main(String[] args) {
compare("010203", "030201");
}
}
- albertchenyu March 04, 2015