//考查运算符的优先级
class Demo{
public static void main(String[] args){
int x=0,y=1;
if(++x==y-- & x++==1||--y==0)
System.out.println("x="+x+",y="+y);//x=2
else
System.out.println("y="+y+",x="+x);//y=0
}
}
2、在注释处按提示写代码
int n = 5,m = 13;
//插入代码,实现n和m值的交换
int tepa;
tepa = n;
n = m;
m = tepa;
System.out.println("n="+n+",m="+m);
3、在打印语句上面写出计算过程,右侧写出输出结果。
++在前先自增,在赋值,++再后先赋值在自增。
class Demo{
public static void main(String[] args){
int a=3,b=8;
int c=(a>b)?a++:b++;
//
System.out.println("a="+a+"\tb="+b+"\tc="+c); //
a大于b是first,所以b增值,b直接赋值到c,a不变,a=3,b=9,c=8
int d=(a>b)?++a:++b;
//
System.out.println("a="+a+"\tb="+b+"\td="+d); //
a大于b是first,所以b自增,d等于b,a不变, a=3,b=9,d=9
int e=(a<b)?a++:b++;
//
System.out.println("a="+a+"\tb="+b+"\te="+e); //
a小于btrue,所以a赋值e,在自增,a=3,e=4,b=8,
int f=(a<b)?++a:++b;
//
System.out.println("a="+a+"\tb="+b+"\tf="+f); //
a小于btrue,a自增在赋值, a=4,f=4,b=8。
}
package Zuoye;
public class pay {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int a1 = 245;
int a2 = 572;
int a3 = 320;
int b1 = 2;
int b2 = 1;
int b3 = 1;
int sum1=a1*b1;
int sum2=a2*b2;
int sum3=a3*b3;
double sum=(sum1+sum2+sum3);
double f=sum*0.8;
System.out.println("总金额"+f);
Scanner input = new Scanner (System.in);
/*System.out.println("************消费单********");
System.out.println("购买物品\t\t单价\t\t个数\t\t金额");
System.out.println("T恤\t\t¥245\t\t2\t\t人民币\t\t¥490");
System.out.println("网球鞋\t\t¥570\t\t1\t\t¥570");
System.out.println("网球拍\t\t¥320\t\t1\t\t¥320");
System.out.println("折扣\t\t8折");
System.out.println("消费总金额\t\t¥1104");
System.out.println("实际付款");
int a1 = input.nextInt();
int c = 396;
int d = a1-c;
System.out.println("找钱"+d);
int e = 1104;
int f = e-100;
double f3 = f/3;
System.out.println("积分"+f3);*/
/*System.out.println("请输入会员卡号0");
int a1 = input.nextInt();
int ge = a1%10;
int shi = a1%100/10;
int bai = a1/100%10;
int qian = a1/1000;
int t = ge+bai+shi+qian;
System.out.println("会员卡号各位之和"+t);
boolean c5 = (t>20)?true:false;
System.out.println("幸运客户"+c5);*/
System.out.println("请输入折扣:");
double zhekou=input.nextDouble();
int a = 245;
int b = 570;
int c = 320;
double e=a*zhekou;
double f=b*zhekou;
double v=c*zhekou;
boolean a1 = (e>100);
boolean b1= (f>100);
boolean c1 = (v>100);
System.out.println("T恤折扣价低于100吗?"+a1+"\n网球鞋折扣价低于100吗?"+b1+"\n网球拍折扣价低于100吗?"+c1);
}
}