1.数据类型:
整数:byte(一个字节,-128~127) short(2字节,16位)int(4字节,32位)long(8字节,64位)
小数:float(4字节,32位,保留六位小数)double(8字节,64位,保留十三位小数)
boolean:一位,true false,逻辑运算
char:两字节,16位
char a='1'; float d=1.4f; double c=14.8; long w=122334l;
在java中,小数被看做double类型,整数按大小范围判定
2.数据类型转换:
容量小的类型默认转换为容量大的数据类型;数据类型按容量大小排序为:
byte,short,char->int->long-
>float->double
byte,short,char之间不会互相转换,他们三者在计算时首先回转换为int类型 容量大的数据类型转换为容量
小的数据类型时,要加上强制转换符,但可能造成精度降低或溢出;使用时要格外注意。 有多种类型的数据混
合运算时,系统首先自动的将所有数据转换成容量最大的那一种数据类型,然后再进行计算。
实数常量默认为 double。整数常量默认为 int 。
int i=5*5.0-'A';按最大类型转换,报错,应为 int i=(int)(5*5.0-'A');
3.运算符:
算术运算符: +,-,*,/,%,++,-- 关系运算符: >,<,>=,<=,= =,!=
逻辑运算符: !,& , | , ^ , &&,|| &&,||和!只能用于boolean 位运算符: &,|,^,~ , >>,<<
,>>>
赋值运算符: =
扩展赋值运算符:+ =,- =,* =,/ =
字符串连接运算符:+
public class gc{
public static void main(String[] s){
/*int i=1,j=2;
float f1=0.1F;
float f2=123;
long l1 = 12345678L,l2=8888888888L;
double d1 = 2e20,d2=124;
byte b1 = 1,b2 = 2,b3 = (byte)129;
j = j+10;i = i/10;
i = (int)(i*0.1);
char c1='a',c2=125;
byte b =(byte)( b1-b2);
char c = (char)(c1+c2-1);
float f3 = f1+f2;
float f4 = (float)(f1+f2*0.1);
double d = d1*i+j;
float f = (float)(d1*5+d2);
System.out.print("*");
*/
/*int i1=6,i2=87;
int i=i2++;
System.out.print("i="+i);
System.out.println("i2="+i2);
i=++i2;
System.out.print("i="+i);
System.out.println("i2="+i2);
i=--i1;
System.out.print("i=" + i);
System.out.println(" i1=" + i1);
i = --i1;
System.out.print("i=" + i);
System.out.println(" i1=" + i1);
}
*/
String a="123";
String b="123";
String c=newString("123");
System.out.print(a==b);
}
4.字符串赋值:
String s="abcd"; //引用
String s1=new String("abcd"); //新创建内存空间
==比较地址 equals比较字符串是否相等
public class mm{
public static void main(String[] arg){
/*String a="123";
String b="123";
String c=new String("123");
System.out.println(a==b);
System.out.println(a==c);
System.out.println(a.equals(c));
System.out.print(a.compareTo(c));
*/
//char i=(char)(Math.random()*6.6+'7'); //Math.random()随机数1.0~0.0
//System.out.println(i);
/*int[] a={74,8,887,56,57,78,4};
for(int y:a){
System.out.println(y);
}
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}
*/
}
}
5.if else语句
6.for循环:
public class Test1{
public static void main(String[] s){
/*
System.out.println(100==100?(100==100?(100==100?(100==100?15001:600):600):600):600);
int[] i={12353,12,461,561,315,343,2135,123,453,13,54};
for(int a=0;a<i.length;a++){
int y=i[a];
System.out.println(y);
}
for(int y:i){ //集合 数组
System.out.println(y);
}*/
int[][][] a={
{
{123,123,123},
{2,3},
{1}
},
{
{123,123,123},
{22,33,22,31},
{133}
},
{
{123,123,123},
{2,333,44,1},
{1,42,2,1,1,1,12}
}};
for(int[][] h:a){
for(int[] k:h){
for(int l:k){
System.out.print(l+",");
}
System.out.println();
}
System.out.println("-----------------------------");
int[] i;
int[] i={123,123,12,312,3,123};
int[] i=new int[50]; //数组申请四种方式
int[] i=new int[]{123,123,123,123,123,123};
}
}
}