Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
Eclipse java write a program that computes a css color.
Expert Solution
Check Mark
Step 1: algorithm

// function to convert decimal to hexadecimal
static String decToHexa(int n) {
// char array to store hexadecimal number
char[] hexaDeciNum = new char[2];

// counter for hexadecimal number array
int i = 0;
while (n != 0) {

// temporary variable to store remainder
int temp = 0;

// storing remainder in temp variable.
temp = n % 16;

// check if temp < 10
if (temp < 10) {
hexaDeciNum[i] = (char) (temp + 48);
i++;
} else {
hexaDeciNum[i] = (char) (temp + 55);
i++;
}

n = n / 16;
}

String hexCode = "";
if (i == 2) {
hexCode += hexaDeciNum[0];
hexCode += hexaDeciNum[1];
} else if (i == 1) {
hexCode = "0";
hexCode += hexaDeciNum[0];
} else if (i == 0)
hexCode = "00";

// Return the equivalent
// hexadecimal color code
return hexCode;
}

// Function to convert the
// RGB code to Hex color code
static String convertRGBtoHex(int R, int G, int B) {
if ((R >= 0 && R <= 255) && (G >= 0 && G <= 255) && (B >= 0 && B <= 255)) {

String hexCode = "#";
hexCode += decToHexa(R);
hexCode += decToHexa(G);
hexCode += decToHexa(B);

return hexCode;
}

// The hex color code doesn't exist
else
return "-1";
}

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education