java复习题_java 练习题带答案

标签:

第一题

int x = 1,y=1;

if(x++==2 & ++y==2)

{

x =7;

}

System.out.println("x="+x+",y="+y);//x=2,y=2

---------------------------------------------------

第二题

int x = 1,y = 1;

if(x++==2 && ++y==2)

{

x =7;

}

System.out.println("x="+x+",y="+y);x=2,y=1

---------------------------------------------------

第三题

int x = 1,y = 1;

if(x++==1 | ++y==1)

{

x =7;

}

System.out.println("x="+x+",y="+y);x=7,y=2

---------------------------------------------------

第四题

int x = 1,y = 1;

if(x++==1 || ++y==1)

{

x =7;

}

System.out.println("x="+x+",y="+y);//x=7,y=1

---------------------------------------------------

第五题

boolean b = true;

if(b=false) //如果写成if(b=false)有结果吗?如果有,结果是?

System.out.println("a");

else if(b)

System.out.println("b");

else if(!b)

System.out.println("c");

else

System.out.println("d");

//b

if(b=false)

//c

---------------------------------------------------

第六题

int x = 2,y=3;

switch(x)

{

default:

y++;

case 3:

y++;

case 4:

y++;

}

System.out.println("y="+y);//y=6

1 1.2 已知学生成绩以100分为满分,共分5个等级:A,B,C,D,E。3 90~100为等级A,80~89为等级B,70~79为等级C,4 60~69为等级D,0~59为等级E。5 要求定义一个成绩变量,当成绩变化时,可直接知道该成绩对应的等级。6 例如:当成绩为100时,该学生的等级时A。7

8 classDemo9 {10 //定义一功能,通过给定分数,获取该分数对应的等级。

11 /*

12 1,明确该功能的结果:等级 char13 2,有没有未知内容。分数。int14 */

15 public static String getLevel(intnum)16 {17 charlevel;18 if(num>=90 && num<=100)19 level = ‘A‘;20 else if(num>=80 && num<=89)21 level = ‘B‘;22 else if(num>=70 && num<=79)23 level = ‘C‘;24 else if(num>=60 && num<=69)25 level = ‘D‘;26 else

27 level = ‘E‘;28

29 returnlevel;30 }31 public static voidmain(String[] args)32 {33

34 char ch = getLevel(35);35 System.out.println("level="+ch);36 }37

38 }39

40

41

42

43

44

45 2.46 写出输出结果。47 classDemo48 {49 public static voidmain(String[] args)50 {51 show(0);//15

52 show(1);//14

53 }54 public static void show(inti)55 {56 switch(i)57 {58 default:59 i+=2;60 case 1:61 i+=1;62 case 4:63 i+=8;64 case 2:65 i+=4;66 }67 System.out.println("i="+i);68 }69 }70

71 3.写出输出的结果.72 classDemo73 {74 public static voidmain(String[] args)75 {76 int x=0,y=1;77 if(++x==y--&x++==1||--y==0)78 System.out.println("x="+x+",y="+y);//x=2,y=0

79 else

80 System.out.println("y="+y+",x="+x);81 }82 }83

84

85 4.86 求出1~100之间,即使3又是7的倍数出现的次数?87

88

89

90 5.91 用程序的方式显示出下列结果。92

93 1*1=1

94 1*2=2 2*2=4

95 1*3=3 2*3=6 3*3=9

96 1*4=4 2*4=8 3*4=12 4*4=16

97 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25

98

99

100 6.写出程序结果。101

102 classDemo103 {104 public static voidmain(String[] args)105 {106 int x = 1;107 for(show(‘a‘); show(‘b‘) && x<3; show(‘c‘))108 {109 show(‘d‘);110 x++;111 }112 }113 public static boolean show(charch)114 {115 System.out.println(ch);116 return true;117 }118 }119

120 //a b d c b d c b

标签:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值