標籤:
//整型
public static void TheNumber(){
byte byte1=127;//1位元組 8位 -128——127
short shorT=1200;//2 位元組 16位
int num1=1200;//8位元組 32位
long num2=121L;//8 位元組 64位 long類型建議加L
int num3=0b0000_0000_0000_0000_0000_0000_0000_0011;//jdk1.7 二進位表示 3
int num4=1234_1234;//jdk1.7 12341234
System.out.println(num3);
}
//進位轉換
public static void scaleNumber(){
int num1=10;
String num2=Integer.toBinaryString(num1);//轉為2進位
String num3=Integer.toOctalString(num1);//轉為八進位
String num4=Integer.toHexString(num1);//轉為16進位
}
//浮點類型 浮點類型常量預設是double
public static void floating(){
double d=3.14; //8 位元組
float f=3.14F;// 4位元組
double d2=10e-2;//科學計數法 0.1
//浮點數 會損失精度 如果需求要求嚴格就使用 浮點類型常量預設是double
float f1=0.1f;
double d3=1/10;
}
//字元類型
public static void character(){
char c1=‘q‘;
char c2=‘中‘;//unicode 2個位元組 :0-65535
char c3=‘\‘‘;//\是轉意字元 輸出 ‘
char c4=‘\n‘;//轉意 表示換行
char c5=‘a‘;
int n=c5+2;//99 ASCII碼
char c6=(char)n;//整數轉為 char
//迴圈 列印a-z
for(int i=0;i<26;i++){
char temp=(char)(‘a‘+i);
System.out.println(temp);
}
//在java中 字串被定義為String類型了
String str="ABCDEFG";
}
//是/否
public static void whether(){
boolean boo=false;// 1位元組
}
java 基礎資料型別 (Elementary Data Type)