Sunday, September 24, 2006

Format string conversion

For %b(boolean) : All data types can be passed

For %c(char) : byte, char, short, int

For %d(int) : byte, short, int, long (No char)

For %f(float) : only float and double

For %s(string) : everything

=======================================

public class Test12{
public static void main(String... args){
boolean b = false;
byte by = 2;
char c = 'A';
short s = 7;
int i = 35565;
long l = 2345676436323746l;
float f = 234.567f;
double d = 234.678;
//System.out.printf("%d\t", b);
System.out.printf("%d\t", by);
//System.out.printf("%d\t", c);
System.out.printf("%d\t", s);
System.out.printf("%d\t", i);
System.out.printf("%d\t", l);
//System.out.printf("%d\t", f);
//System.out.printf("%d\t", d);
System.out.println();
System.out.printf("%b\t", b);
System.out.printf("%b\t", by);
System.out.printf("%b\t", c);
System.out.printf("%b\t", s);
System.out.printf("%b\t", i);
System.out.printf("%b\t", l);
System.out.printf("%b\t", f);
System.out.printf("%b\t", d);
System.out.println();
System.out.printf("%s\t", b);
System.out.printf("%s\t", by);
System.out.printf("%s\t", c);
System.out.printf("%s\t", s);
System.out.printf("%s\t", i);
System.out.printf("%s\t", l);
System.out.printf("%s\t", f);
System.out.printf("%s\t", d);
System.out.println();
//System.out.printf("%f\t", b);
//System.out.printf("%f\t", by);
//System.out.printf("%f\t", c);
//System.out.printf("%f\t", s);
//System.out.printf("%f\t", i);
//System.out.printf("%f\t", l);
System.out.printf("%f\t", f);
System.out.printf("%f\t", d);
System.out.println();
//System.out.printf("%c\t", b);
System.out.printf("%c\t", by);
System.out.printf("%c\t", c);
System.out.printf("%c\t", s);
System.out.printf("%c\t", i);
//System.out.printf("%c\t", l);
//System.out.printf("%c\t", f);
//System.out.printf("%c\t", d);
}
}

========================

Output:

2 7 35565 2345676436323746
false true true true true true true true
false 2 A 7 35565 2345676436323746 234.567 234.678
234.567001 234.678000
 A  ?

No comments: