Java Job 7

Source: Internet
Author: User

( 1 ) Read the following code ( Catchwho.java ), write out the program run result:

( 2 ) Write Catchwho2.java Results of program Operation

( 3 ) Please read first Embedfinally.java example, run it again, observe its output, and summarize it.

Summary: when there are multiple layers of nested Finally, exceptions are thrown at different levels and thrown at different locations, which can result in a different order of finally statement block execution.

( 4 according to the analysis of several examples of the program, please self-summarize Java the basic flow of multi-layered nested exception handling.

When the try-catch-finally are nested with each other, the try-catch-finally of the inner layer is processed first. When the try throws an exception that matches the catch, the code executes in the corresponding catch (). If the catch also has an exception, the program detects if there is an exception in finally and overwrites if there is one. If there is only try-finally, then finally is executed, and if finally there is no exception, the exception in the handle try is returned, and if finally there is an exception, the exception in the try is overwritten

( 5 ) Hands -on brain

import javax.swing.*;

Public class Score {

Public Static void Main (String []args) {

int n=0;

Try {

String Str=joptionpane. Showinputdialog ("Please enter student score:");

N=integer. parseint (str);

if (0<=n&&n<60)

{

Joptionpane. Showmessagedialog (null, "failed",

"Student Performance", Javax.swing.JOptionPane. information_message);

}

if (n>=60&&n<70)

{Joptionpane. Showmessagedialog (null, "pass",

"Student Performance", Javax.swing.JOptionPane. information_message);}

if (n>=70&&n<80)

{

Joptionpane. Showmessagedialog (null, "medium",

"Student Performance", Javax.swing.JOptionPane. information_message);

}

if (n>=80&&n<90)

{

Joptionpane. Showmessagedialog (null, "good",

"Student Performance", Javax.swing.JOptionPane. information_message);

}

if (n>=90&&n<=100)

{

Joptionpane. Showmessagedialog (null, "excellent",

"Student Performance", Javax.swing.JOptionPane. information_message);

}

if (n>100)

{

Joptionpane. Showmessagedialog (null, "incorrect input",

"Student Performance", Javax.swing.JOptionPane. information_message);

}

if (n<0)

{

Joptionpane. Showmessagedialog (null, "incorrect input",

"Student Performance", Javax.swing.JOptionPane. information_message);

}}

Catch (Exception e)

{Joptionpane. Showmessagedialog (null, "incorrect input",

"Student Performance", Javax.swing.JOptionPane. information_message);

}}}

Operation Result:

Java Job 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.