• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
秘银徽章
博客园    首页    新随笔    联系   管理    订阅  订阅
java课后作业7

9.页实验

下列语句哪一个将引起编译错误?为什么?哪一个会引起运行时错误?为什么?

m=d;

d=m;

d=(Dog)m;

d=c;

c=(Cat)m;

答:

d=m;和d=c;引起编译错误;

原因:

 

c=(Cat)m;引起运行时错误;

原因:

 

24.页实验

 

25.页实验

 

26.页实验

 

27.页实验

finally语句块一定会执行吗?

答:不一定,1.只有与 finally 相对应的 try 语句块得到执行的情况下,finally 语句块才会执行。 2.在 try 语句块中执行了 System.exit (0) 语句,终止了 Java 虚拟机的运行。3.当一个线程在执行 try 语句块或者 catch 语句块时被打断(interrupted)或者被终止(killed),与其相对应的 finally 语句块可能不会执行。4.在线程运行 try 语句块或者 catch 语句块时,突然死机或者断电,finally 语句块肯定不会执行了。

 

46.页实验

import java.util.InputMismatchException;

import java.util.Scanner;

 

public class Test {

 

public static void main(String[] args) {

// TODO 自动生成的方法存根

int cj;

boolean boo=true;

for(;;)

{

try

{

System.out.println("请输入成绩:");

Scanner input=new Scanner(System.in);

cj=input.nextInt();

if(cj<0)

{

System.out.println("输入的成绩不在0到100的范围内!");

boo=false;

}

else{

if(cj<60)

{

System.out.println("不及格!");

boo=true;

}

else

{

if(cj<=70)

{

System.out.println("及格!");

boo=true;

}

else

{

if(cj<=80)

{

System.out.println("中等!");

boo=true;

}

else

{

if(cj<=90)

{

System.out.println("良好!");

boo=true;

}

else

{

if(cj<=100)

{

System.out.println("优秀!");

boo=true;

}

else

{

System.out.println("输入的成绩不在0到100的范围内!");

boo=false;

}

}

}

}

}

}

}

catch (InputMismatchException e)

{

System.out.println("输入错误!");

boo=false;

}

if(boo==true)

{

break;

}

}

}

}

 

 

posted on 2015-11-13 16:38  秘银徽章  阅读(173)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3