Question

Question 11 (20 points) Using your choice of language, C# or Java (no pseudocode allowed), give a format/template of Exceptio JAVA
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans)

try catch and finally:

//used 1/0 to raise ArthmaticException

public class Test {

public static void main(String[] args) {

    int divident = 5;

    int divider=0;

    float result;

    try {

        result = divident / divider; //(1/0) exception will raise

    } catch (ArithmeticException e) { //will handle the exception

        System.out.println("Error Message : "+e.getMessage()+" exception occured");

    }

    finally { //excecute at end

        System.out.println("Thanku for using your Service");

    }

}

    

}

Add a comment
Know the answer?
Add Answer to:
JAVA Question 11 (20 points) Using your choice of language, C# or Java (no pseudocode allowed),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using your choice of language, C#, Java, or pseudocode, write a recursive method that receives only...

    Using your choice of language, C#, Java, or pseudocode, write a recursive method that receives only one parameter, an int n, and prints the cubed of the numbers from 1 to n3 in ascending order. Do not use any global variables or stacks. For example, passing this method the value 5, the output would be “1    8    27    64    125”. Because 13 = 1, 23 = 8, 33 = 27, 43 = 64 and so on

  • Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

    Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...

  • JAVA Question 16 (6 points) Given an empty Queue q and empty Stacks. Show what Q...

    JAVA Question 16 (6 points) Given an empty Queue q and empty Stacks. Show what Q and will look like after the following instructions are executed." for(int i = 0; i < 6; i++){ qenqueuei-2): s push(i-4). while(! q.isEmpty) iffe peek() %2 == 0){ s pop(); 5 push(q.dequeue): else { s.popO: 9.dequete: } www qenqueue speeko): Format BIU $ Question 17 (6 points) The following code defines an exception myException. It is used in testl (String str) and the testl...

  • JAVA Which of these statements does not match by using exception action in Java? 1. Exception...

    JAVA Which of these statements does not match by using exception action in Java? 1. Exception action makes it possible for the calling method to handle errors in called methods.    2. Exception action simplifies programming since incorrect reporting and handling can be located in catch blocks separately from the rest of the code.    3. Exception action increases the performance of programs. 4. Java separates exception action from common processes. Why create instances of File Class? - several alternatives...

  • Java programming: The feedback I received "responds badly to bad input. Fix 2" Original question: Write...

    Java programming: The feedback I received "responds badly to bad input. Fix 2" Original question: Write a program that creates a small (6-10) array of ints. Display your array elements, all on one line, using a foreach loop. In a try block, prompt the user to enter an index for the array and attempt to print the element with that index. Follow the try block with two catch blocks; one that detects an index out of bounds, and another that...

  • CSC151 JAVA PROGRAMMING LAB #7 OBJECTIVES . . . In this lab assignment, students will learn:...

    CSC151 JAVA PROGRAMMING LAB #7 OBJECTIVES . . . In this lab assignment, students will learn: To get an overview of exceptions and exception handling • To explore the advantages of using exception handling • To declare exceptions in a method header • To throw exceptions in a method • To write a try-catch block to handle exceptions To develop applications with exception handling To use the finally clause in a try-catch block To write data to a file using...

  • Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment...

    Advanced Object-Oriented Programming using Java Assignment 4: Exception Handling and Testing in Java Introduction -  This assignment is meant to introduce you to design and implementation of exceptions in an object-oriented language. It will also give you experience in testing an object-oriented support class. You will be designing and implementing a version of the game Nim. Specifically, you will design and implement a NimGame support class that stores all actual information about the state of the game, and detects and throws...

  • Please write this in Java, please write comments as you create it, and please follow the...

    Please write this in Java, please write comments as you create it, and please follow the coding instructions. As you are working on this project, add print statements or use the debugger to help you verify what is happening. Write and test the project one line at a time. Before you try to obtain currency exchange rates, obtain your free 32 character access code from this website: https://fixer.io/ Here's the code: 46f27e9668fcdde486f016eee24c554c Choose five international source currencies to monitor. Each...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT