实验一.docx
《实验一.docx》由会员分享,可在线阅读,更多相关《实验一.docx(15页珍藏版)》请在冰豆网上搜索。
![实验一.docx](https://file1.bdocx.com/fileroot1/2023-6/6/1be0c4f9-c834-420a-ba40-d578f8c9cdb1/1be0c4f9-c834-420a-ba40-d578f8c9cdb11.gif)
实验一
实验一
1.publicclassaaa
{publicstaticvoidmain(String[]args)
{Stringstr2=3.5f+"";
System.out.println(3+4+"hello");
System.out.println("hello"+3+4);}
}
结果:
7hellohello34
2.publicclassbbb
{publicstaticvoidmain(String[]args){intiValue=233;
bytebValue=(byte)iValue;
System.out.println(bValue);
doubledValue=3.98;
inttoI=(int)dValue;
System.out.println(toI);}}
结果:
-233
3.publicclassccc
{publicstaticvoidmain(String[]args)
{Stringresult="";
for(inti=0;i<6;i++)
{intintVal=(int)(Math.random
()*26+97);
result=result+(char)intVal;}
System.out.println(result);}
}
结果:
xcgpvx
4.publicclassddd
{publicstaticvoidmain(String[]args)
{inti=3;
System.out.println(i++);
System.out.println(++i);}
}
结果:
35
5.publicclasseee
{publicstaticvoidmain(String[]args)
{inti=3;
intcount=(i++)+(i++)+(i++);
System.out.println(i);
System.out.println(count);}
}
结果:
612
6.publicclassfff
{publicstaticvoidmain(String[]args)
{inti=3;
intcount=(++i)+(++i)+(++i);
System.out.println(i);
System.out.println(count);}
}
结果:
615
7.publicclassggg
{publicstaticvoidmain(String[]args)
{
System.out.println(5&9);
System.out.println(5|9);
System.out.println(~-5);
System.out.println(5^9);
System.out.println(5<<2);
System.out.println(-5<<2);
System.out.println(-5>>2);
System.out.println(-5>>>2);
}
}
结果:
11341220-20-21073741822
8.publicclasshhh
{publicstaticvoidmain(String[]args)
{inta=5;
intb=10;
if(a>4|b++>10)
{System.out.println("a的值是;"+a+"b的值是"+b);}
intc=5;
intd=10;
if(c>4||d++>10)
{System.out.println("c的值是;"+c+"d的值是"+d);}
}
}
结果:
a:
5b:
11c:
5d:
10
9.publicclassiii
{publicstaticvoidmain(String[]args)
{inta=5;
intb=10;
if(a>4&b++>10)
{System.out.println("a的值是;"+a+"b的值是"+b);}
intc=5;
intd=10;
if(c>4&&d++>10)
{System.out.println("c的值是;"+c+"d的值是"+d);}
}
}
结果为空
10.publicclassjjj
{publicstaticvoidmain(String[]args)
{Stringstr=5>3?
"5大于3":
"5不大于3";
System.out.println(str);
}
}
结果:
5大于3
课本习题:
2.原程序:
publicclasskkk
{publicstaticvoidmain(String[]args)
{ch='a';
charch;
System.out.println("ch="+ch);
}
}
改后:
publicclasskkk
{publicstaticvoidmain(String[]args)
{charch;
ch='a';
System.err.println("ch="+ch);
}
}
结果:
ch=a
3.publicclasslll
{publicstaticvoidmain(String[]args)
{intx=1,a=0,b=0;
switch(x){
case0:
b++;
case1:
a++;
case2:
a++;b++;}
System.out.println("a="+a);
System.out.println("b="+b);
}
}
结果:
a=2b=1
4.
(1)
publicclassA
{publicstaticvoidmain(String[]args)
{inta=1,b=2,c=3;
System.out.println(a+b--/++c);
}
}
结果:
1
(2)
publicclassB
{publicstaticvoidmain(String[]args)
{inta=1,b=2,c=3;
booleand=false;
d=!
(a>=--b/b++&&c-->=--b/b++)&&a==b;
System.out.println(d=!
(a>=--b/b++&&c-->=--b/b++)&&a==b);
}
}
结果:
false
(3)
publicclassC
{publicstaticvoidmain(String[]args)
{inta=1,b=2,c=3;
booleand=false;
System.out.println(d==b>c^a!
=c);
}
}
结果:
false