0
Sample code?
Can anyone please provide a sample java code?
4 Respostas
+ 3
you have plenty sample codes in the java tutorial in this app.
+ 1
public class MyJavaProg{
public static void main(String[] args){
PrintYourFunction();
}
public void PrintYourFunction(){
System.ou.println("My first Java Program to print something");
}
}
0
class Demo
{
static int red=134;
static int green=255;
static int blue=27;
static String[] letters={"A", "B", "C", "D", "E", "F"};
static String red1,red2,green1;
static String green2,blue1,blue2;
public static String toHex(int r, int g, int b){
int r1= (int) Math.floor(r/16);
if(r1>9){
red1=letters[r1-10];
}
else{red1=String.valueOf(r1);}
int r2= (int) r%16;
if(r2>9){
red2=letters[r2-10];
}
else{red2=String.valueOf(r2);}
int g1= (int) Math.floor(g/16);
if(g1>9){
green1=letters[g1-10];
}
else{green1=String.valueOf(g1);}
int g2= (int) g%16;
if(g2>9){
green2=letters[g2-10];
}
else{green2=String.valueOf(g2);}
int b1= (int) Math.floor(b/16);
if(b1>9){
blue1=letters[b1-10];
}
else{blue1=String.valueOf(b1);}
int b2= (int) b%16;
if(b2>9){
blue2=letters[b2-10];
}
else{blue2=String.valueOf(b2);}
String hex1=red1+red2+green1;
String hex2=green2+blue1+blue2;
String hex="#" + hex1+hex2;
return hex;
}
public static void main (String[] args) throws java.lang.Exception
{
System.out.println(toHex(red,green,blue));
}
}
I wrote this the other day. Turns RGB into Hexadecimal. I used it as a function in my Color picker program. as seen here http://leakyegg.website.tk/RGB.zip if your on a pc, feel free to download it
0
class Test{
public static void main(String tst[]){
System.out.println("My name is Udara");
}
}