1 public class ShuJuZhuanHuan { 2 public static void main(String[] args) { 3 int a1=123 ; 4 int a2=456 ; 5 double b1=(a1+a2)*1.2; // The system will convert to double operation 6 float c1=( float )((a1+a2)*1.2); // Needs strong conversion character 7 byte d1=1 ; 8 byte d2=2 ; 9 byte d3=( byte )(d1+d2); / / The system will convert to int type operation, which requires coercion 10 double b2= 1e200; 11 float c2=( float )b2; // will overflow 12 System.out.println(c2); 13 float c3=1.23f; // must add f 14 long e1=123 ; 15 long e2 =3000000000000L; // Must add L 16 float c4 =e1+e2+c3; // The system will convert to float for calculation 17 long e=( long )c4; // Force conversion will round off the fractional part (not round off) 18 } 19 }
1 float f1=0.1; // If there is a problem, add F or cast 2 long L1=8888888888; // Need to add L 3 i=1/10; // The result is 0 4 i=(i*0.1); // double Casting to int is lost
Program format:
a: brace alignment
b:Tab/Shift+Tab
c: add blank lines between program blocks
d: space between side-by-side statements
e: space around the operator
f:{ is preceded by a space
g: Pair programming