变量

1.变量:值可以发生改变。(一个数据存储空间表示)

2.数据类型:基本数据类型和引用数据类型。

   2.1基本数据类型:数值型,字符型,布尔型。

           2.1.1数值型:整数(byte 1字节,short 2字节,int  4字节 long  8字节).和浮点型(float  4字节,double 8字节)。

             2.1.2字符型:char

                2.1.3:布尔型boolean

2.2引用型:类class,接口interface,数组[].

3.数据类型转换:大转小(强制转换)

byte short在运算类型时提升为int

例如:

byte b1=3,b2=4,b;

b=b1+b2; b=3+4;

哪句是编译失败的呢?为什么呢?

答b=b1+b2,因为运算时提升为int

所以这样写:b=(byte)(b1+b2)

     leg:

System.out.println(‘a’);//a

System.out.println(‘a’+1);//98

System.out.println(“hello”+’a’+1);//

System.out.println(‘a’+1+”hello”);//98hello

System.out.println(“5+5=”+5+5);//5+5=55

System.out.println(5+5+”=5+5”);//10=5+5

面试题:

int x = 0;
int y = 0;
//System.out.println(x++);//0
//System.out.println(++y);//1
//int k = ++x + 1 + ++x +x;//求k的值? 6
//1 + 1 + 2 +2
//int k = x++ + x++ + x; //3
//0 + 1 + 2
int k = y++ + ++y + y++ +y + ++y;//11
//0 + 2 + 2 +3 + 4
System.out.println(k);

若x=0;

++x后++x=1;x=1

x++后x++=0;但x=1

4.运算符:算术运算    关系运算 逻辑运算 位运算 三目运算

算术运算:+   -   *   /  %  ++   --

关系运算:>   <     >=      <=  ==  !=

逻辑运算符:&&与   ||或  !非    异或^

位运算:单&  两边是数字是进行与运算

             单|  两边是数字是进行或运算

           异或^

取反,得到的是补码

三目运算:(关系表达式)?表达式1:表达式2

5.条件判断if  switch

if的语法格式语法   if ...if     

if...else

if...else if

原文地址:https://www.cnblogs.com/hdj1073678089/p/7246117.html