zoukankan      html  css  js  c++  java
  • 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;

    }

    }

    }

    }

     

  • 相关阅读:
    POJ 2236 Wireless Network(并查集)
    POJ 2010 Moo University
    POJ 3614 Sunscreen(贪心,区间单点匹配)
    POJ 2184 Cow Exhibition(背包)
    POJ 1631 Bridging signals(LIS的等价表述)
    POJ 3181 Dollar Dayz(递推,两个long long)
    POJ 3046 Ant Counting(递推,和号优化)
    POJ 3280 Cheapest Palindrome(区间dp)
    POJ 3616 Milking Time(dp)
    POJ 2385 Apple Catching(01背包)
  • 原文地址:https://www.cnblogs.com/gzgz/p/4962533.html
Copyright © 2011-2022 走看看