Question

What is the output of the following question? import java.io.IOException; import java.util. EmptyStackException: public class

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment. Please rate answer as well. Thanks

Answer : 145

Explanation: First it will print from main function as 1. Then it will throw exception. If you see Catch blocks, they are catching specific exceptions first and then moving on to general exception. Because we are throwing general exception of type Exception class, it will be caught by 3rd catch block. Which will print 4. And then finally block will be executed and it will print 5.

Finally block will always be executed irrespective of which catch is executed.

----GRASP exec: java newclass 145 ----GRASP: operation complete.

Add a comment
Know the answer?
Add Answer to:
What is the output of the following question? import java.io.IOException; import java.util. EmptyStackException: public class newclass...
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
  • package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public...

    package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public static void main (String [] args)    {    // ============================================================    // Step 2. Declaring Variables You Need    // These constants are used to define 2D array and loop conditions    final int NUM_ROWS = 4;    final int NUM_COLS = 3;            String filename = "Input.txt";    // A String variable used to save the lines read from input...

  • Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public...

    Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • Question 2: Execute the following program. import java.util.Arrays; public class ArrayManipulations { public static void main(String[]...

    Question 2: Execute the following program. import java.util.Arrays; public class ArrayManipulations { public static void main(String[] args) { // sort doubleArray into ascending order char [] A = {'g', ', 'y', 'a', 'e','d' }; Arrays.sort( A); for (char value: A) System.out.printf("%2C", value); System.out.printf("\n"); char [] A Copy = new char[ 3 ]; System.arraycopy( A, 2, A Copy, 0, A Copy.length); for(char value: A Copy) System.out.printf("%2C", value); System.out.printf("\n"); int location = Arrays.binary Search(A Copy, 'y'); if(location >=0) System.out.printf("y Found at element...

  • I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public...

    I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public static void main(String[] args) {         if (args.length !=1) {             System.out.println(                                "Usage: java wordcount2 fullfilename");             System.exit(1);         }                 String filename = args[0];               // Create a tree map to hold words as key and count as value         Map<String, Integer> treeMap = new TreeMap<String, Integer>();                 try {             @SuppressWarnings("resource")             Scanner input = new Scanner(new File(filename));...

  • (1) (5 points) What does the following codes display? import java.util.; public class Test public static...

    (1) (5 points) What does the following codes display? import java.util.; public class Test public static void main(Stringl) args) PriorityQueuecinteger> queue - new PriorityQueuecintege>( Arrays.asList(60, 10, 50, 30, 40, 20)); while (lqueue.isEmpty)) System.out.print(queue.poll()+"") The program displays 60 10 50 30 40 20 b. The program displays 60 50 40 30 20 10 c. This problem displays 10 30 50 20 40 60 d. The program displays 10 20 30 40 50 60 e. There is no guarantee that the program...

  • What is output 1 in the code below? import java.util."; public class StackDemo { public static...

    What is output 1 in the code below? import java.util."; public class StackDemo { public static void main(String [] args) { Stack<Integer> intStack = new Stack<>(); Stack<Integer> tempStack = new Stack<>(); intStack.push(18); intStack.push(21); intStack.push(25); tempStack = intStack; while (!tempStack.empty() { System.out.print(tempStack.peek()+"");//output 1 tempStack.pop(); 3 System.out.println(); System.out.println(intStack.peek()); //output 2 25 18 21 • 25 21 18

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • Please help, Array does not print properly. I need to print out the 8 class numbers...

    Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial {    public static void main(String[] args) {    int newclass = 0;    int countclass = 0;    final int class_Max = 8;    int[] classarray =...

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
ADVERTISEMENT