1 answer

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

Question:

Question 16 (6 points) Given an empty Queue q and empty Stacks. Show what Q and will look like after the following instructio

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 (String str) method is called in test2(). There are three errors in the following code, correct it public class myException extends Exception public myException super"Don't he silly.") public void test(String str) throw myException if str.compare To "nervous")0) throw mylixception System.out.println("Today is a good day for a good day"); 1 public void test20 try! lea!"hello: catch System.out.println("This is the end.");

Answers

Q16. Since Queue maintains FIFO order i.e., elements which entered first will be removed first. While Stack follows LIFO order i.e., elements which enter last will come out first .

So the elements present in q: 7

Elements present in s: (Top ---- > Bottom) 7,5,4

Q.17 NOTE: Error are marked in Bold.

Error 1 : public void test1(String str) throws myException{

Error 2:  if(str.compareTo("nervous")==0)
throw new myException();

Error 3:  public void test2(){

try{

test1("hello");

}

catch (myException e){

  System.out.println("This is the end");

}

}

.

Similar Solved Questions

1 answer
According to a study conducted in one​ city, 32​% of adults in the city have credit...
According to a study conducted in one​ city, 32​% of adults in the city have credit card debts of more than​ $2000. A simple random sample of n=200 adults is obtained from the city. Describe the sampling distribution of p​, the sample proportion of adults who have credit card...
1 answer
Question 8 Graph the function. Use the graph of f(x) = 4 * to obtain the...
Question 8 Graph the function. Use the graph of f(x) = 4 * to obtain the graph of g(x) = 4 *-1 -2...
1 answer
Under the revenue recognition principle, a good or service is considered transferred when A. all performance...
Under the revenue recognition principle, a good or service is considered transferred when A. all performance obligations have been specified B. the business has received cash from the customer OC. the customer obtains control of the good or service D. the transaction price has been agreed to...
1 answer
Discuss how you live a healthy lifestyle and if you encourage others to do the same...
Discuss how you live a healthy lifestyle and if you encourage others to do the same......
1 answer
Consider the following reaction: 2Na + Cl2  2NaCl ΔH = -821.8 kJ (a) Is the reaction exothermic or endothermic
Consider the following reaction: 2Na + Cl2  2NaCl ΔH = -821.8 kJ (a) Is the reaction exothermic or endothermic? (b) Calculate the amount of heat transferred when 5.6 g of Na reacts at constant pressure. (c) How many grams of NaCl are produced during an enthalpy change of 16.5 kJ? (d) H...
1 answer
Please help....I don't know what solution to use and what the final answer is that I should get
The tungsten filament of alight bulb has an operating temperature of about 2100 K. If theemitting area of the filament is 1.0 cm2,and itsemissivity is 0.68, what is the power output of the light bulb?(α=5.67 * 10-8W/m2*K4)...
1 answer
Required information [The following information applies to the questions displayed below.] Income statements and balance sheets...
Required information [The following information applies to the questions displayed below.] Income statements and balance sheets data for Virtual Gaming Systems are provided below. VIRTUAL GAMING SYSTEMS Income Statements For the years ended December 31 2022 2021 Net sales $3,545,000 $3,071,000 Cost ...
1 answer
List and explain the five schedules of drugs?
list and explain the five schedules of drugs?...
1 answer
Your Cabaret nightspot "Jazz on Jupiter" has become an expensive proposition: You are paying monthly costs...
Your Cabaret nightspot "Jazz on Jupiter" has become an expensive proposition: You are paying monthly costs of  $60,000 just to keep the place running. On top of that, your regular cabaret artist is charging you $3900 per performance, and your jazz ensemble is charging $1200 per hou...
1 answer
Prepare Store Ledger Card (SLC) form the following information on Jan 2017: 1. Opening Stock .........................400...
Prepare Store Ledger Card (SLC) form the following information on Jan 2017: 1. Opening Stock .........................400 units @ Rs. 30 ..... Rs. 12,000 2. Purchases.... ...200 units @ Rs. 28.. ..Rs. 5,600 15. Sales ........ ..........125 units @ ........ 21. Purchases ..... ............80 units @ ...
1 answer
What is the product of the reaction? Part B HO OH, HCI Draw the molecule on...
What is the product of the reaction? Part B HO OH, HCI Draw the molecule on the canvas by choosing buttons from the Tools (for bonds), Atoms, and Advanced Template toolbars. The single bond is active by default....
1 answer
PLEASE ANSWER ALL QUESTION WHICH ONE IS MISSING. THANK YOU SO MUCH. ロvelocity vs. nme Graph...
PLEASE ANSWER ALL QUESTION WHICH ONE IS MISSING. THANK YOU SO MUCH. ロvelocity vs. nme Graph A ball is thrown straight up into the air and then, on the way back down, is caught at the same height it was released at. For the following graphs, UP IS POSITIVE & DOWN IS NEGATIVE. Assume there ...
1 answer
Problem #6 m Di ZR S T In the following circuit, L1= 5 mH, L2= 2...
Problem #6 m Di ZR S T In the following circuit, L1= 5 mH, L2= 2 mH, R= 9.9 Ohm, C= 10 uF. Find the average power delivered by the ideal current source if ig=50cos(10000t) mA. (Unit: W) Submit Answer Tries 0/3...
1 answer
Dt dt Poe 2), 3) 4) dt dt Poe 2), 3) 4)
dt dt Poe 2), 3) 4) dt dt Poe 2), 3) 4)...
1 answer
Please provide ICD-10-CM codes The patient is a 55-year-old male who is brought to the emergency...
please provide ICD-10-CM codes The patient is a 55-year-old male who is brought to the emergency room by his family. Tell the physician that over the past two weeks the patient has had difficulty walking to int that today, he cannot walk at all. The emergency physician identifies the problem progres...
1 answer
9.2.7 Determine the t-value in each of the cases Click the icon to view the table...
9.2.7 Determine the t-value in each of the cases Click the icon to view the table of areas under the t-distribution (a) Find the t-value such that the area in the right tail is 0.005 with 11 degrees of freedom. (Round to three decimal places as needed.)...