The following two codes are executed for which a wrong input of 4.3 is entered. How...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The following two codes are executed for which a wrong input of 4.3 is entered. How the execution of these codes will be different and why? [2 points] import java.util.Scanner; import java.util.InputMismatchException; import java.util.InputMismatchException; import java.util.Scanner; public class Q1 { public static void main(String [] args) { public class Q3 { public static void main(String [] args) { int num = getNumber(); System.out.println("The entered number is: " + num); int num = getNumber(); System.out.println("The entered number is: " +num); public static int getNumber() { public static int getNumber() { Scanner sc = new Scanner(System. in); int input = e; boolean finished = false; while (Ifinished) { Scanner sc = new Scanner (System. in); int input = 0; boolean finished = false; while (Ifinished) { try { System.out.print("Enter a whole number:"); input = sc.nextInt(); finished = true; } catch (InputMismatchException e) { sc.nextline(); System.out.println("Wrong Input, try again..."); System.exit(e); try { System.out.print ("Enter a whole number:"); input = sc.nextInt(); finished = true; catch (InputMismatchException e) { sc.nextline(); System.out.println("Wrong Input, try again..."); } return input; } return input; The following two codes are executed for which a wrong input of 4.3 is entered. How the execution of these codes will be different and why? [2 points] import java.util.Scanner; import java.util.InputMismatchException; import java.util.InputMismatchException; import java.util.Scanner; public class Q1 { public static void main(String [] args) { public class Q3 { public static void main(String [] args) { int num = getNumber(); System.out.println("The entered number is: " + num); int num = getNumber(); System.out.println("The entered number is: " +num); public static int getNumber() { public static int getNumber() { Scanner sc = new Scanner(System. in); int input = e; boolean finished = false; while (Ifinished) { Scanner sc = new Scanner (System. in); int input = 0; boolean finished = false; while (Ifinished) { try { System.out.print("Enter a whole number:"); input = sc.nextInt(); finished = true; } catch (InputMismatchException e) { sc.nextline(); System.out.println("Wrong Input, try again..."); System.exit(e); try { System.out.print ("Enter a whole number:"); input = sc.nextInt(); finished = true; catch (InputMismatchException e) { sc.nextline(); System.out.println("Wrong Input, try again..."); } return input; } return input;
Expert Answer:
Answer rating: 100% (QA)
The execution of the code will be different in both the cases as In first case even if we ... View the full answer
Related Book For
The Legal Environment of Business A Critical Thinking Approach
ISBN: 978-0132664844
6th Edition
Authors: Nancy K Kubasek, Bartley A Brennan, M Neil Browne
Posted Date:
Students also viewed these chemical engineering questions
-
RUN THE CODE import java.security.MessageDigest; public class MD5Digest { public static void main(String[] args) throws Exception { //Copy and paste this section of code String original = "letmein";...
-
A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is mapped, row-wise, to a 1D-array of size 28: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...
-
The industry demand curve for a particular market is: Q = 1800 - 200P. The industry exhibits constant long-run average cost at all levels of output, regardless of the market structure. Long-run...
-
Identify an accurate sentence about parenting in the United States. a. Fathers of toddlers play more roughly with daughters than with sons. b. During the first year, fathers treat boys and girls as...
-
Radiation from a point source obeys the inverse-square law. If a Geiger counter 1 m from a small sample registers 360 counts per minute, what will be its counting rate 2 m from the source? What will...
-
Contrast the investment risk potentials of an electric vehicle manufacturer whose shares have a PE ratio of 10:1 and a coal company whose stock has a PE ratio of 2.5 to 1.
-
An air-standard Otto cycle has a compression ratio of 6. The temperature at the start of compression process is \(25^{\circ} \mathrm{C}\) and the pressure is 1 bar. If the maximum temperature of the...
-
Given the following data, on a separate sheet of paper create monthly and yearly income statements for this fast-food restaurant in New York City. a. Sales for the month of June were $300,000. Sales...
-
Explore the application of thermodynamic analysis to environmental and ecological systems, addressing concepts such as energy flow, entropy production, and emergent behaviors in ecosystems, and their...
-
Consider the novel device for oxidative treatment of wastewater shown in the figure (right column). In this device, O 3 will serve as the oxidant source, which must be carefully dosed into the...
-
Use the graph above to answer the following question. If the price is set to $3, what is the producer surplus in the market? Note: enter answer with only numerical values and round up to the nearest...
-
An 115.4 kg runner takes a corner with a radius of 6.31 m. What centripetal acceleration (in m/s2) is necessary if they were travelling at 7.95 m/s? a. Not shown here. Ob. 10.0 c. 0.0998 d. 39.8 e....
-
(5pt) Hollow circular post ABC supports a compressive load P = 2100 lb. A second load P2 is uniformly applied to the cap plate at B, and can be treated as a single concentrated load of magnitude P2....
-
Determine the magnitude of the maximum magnetic force that could be proton of mass 1.67x10-27 kg and charge 1.6x10-19 C moving through a magnetic field of magnitude 1.50 T at a speed of 6.00x106 m/s....
-
At a given time, the global position vector of the origin of the body coordinate system is defined by the vector [-5.0 10] m. The orientation of the body coordinate system is defined by the angle 0 =...
-
In the 2003 film Pirates of the Caribbean: Curse of the Black Pearl, there is a scene in which Jack and Will steal (Commandeer. Nautical term.) a ship of the fleet. They disable the Dauntless...
-
Question 4. Use your function from above to simulate the drawing of 13 cards 5000 times under the proportions that you specified in Question 1. Keep track of all of your statistics in deck statistics...
-
What are the six activities involved in the physical supply/distribution system?
-
McGraw and Duffy have a contract that includes a binding arbitration clause. The clause provides for arbitration of any dispute arising out of the contract. The clause also provides that the...
-
Thomas Woeste ordered raw oysters at Washington Platform Saloon and Restaurant. After eating the oysters, Woeste died as a result of contracting the bacterium Vibrio vulnificus. Vibro vulnificus is a...
-
In August 1998, Jea Yu contacted Cameron Eppler, president of Design 88, Ltd., to discuss developing a Web site that would cater to investors and provide services to its members for a fee. Yu and...
-
Describe the process of going public using an IPO, starting with underwriter selection and proceeding through the various stages that lead to determination of an issue price.
-
Identify at least four methods by which investors and/or the entrepreneur in a new venture can harvest their investment in a new venture. Describe the costs and benefits of each, and provide a...
-
From the perspective of the entrepreneur, what are the pros and cons of an IPO as opposed to private sale of the venture to a public company in exchange for stock or cash?
Study smarter with the SolutionInn App