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...
-
Three-month sterling interest-rate futures are quoted as follows on 30 August: 500,000 points of 100% Settlement price September ......................... 91.50 December ............................
-
How will you respond to Janet? Janet is a young (early 20s) new staff member who has been working on community program with Jason a more experienced older staff member in your organisation. You have...
-
Discuss the ratios computed for Tyler Company in problems 13 through 16. What is your assessment of the performance and future potential of Tyler Company? Data From Problem 13:- The following reserve...
-
Are there any levers that Kirsten can use to counteract the reason and rationalizations and persuade Matt about the right thing to do?
-
Suppose that a fund manager has a portfolio of stocks currently worth (in total) 100,000 and that on the market there are a call and a put option contracts available on the same assets of the...
-
Bronys Bikes maintains two general demand deposit bank accounts and an imprest payroll account. One of the general bank accounts and the payroll account are with Dallas Dollar Bank. The second demand...
-
Integrate: 1. (8 points) . Ina da 2. (8 points) tan tan x sec x dx 3. (10 points) 4. (10 points) 1 J X 16-x x 7.3 dx x +9 5. (14 points) Are the following improper integrals convergent? Exp If...
-
You hold one end of a horizontal string and raise your hand during a time interval of \(0.18 \mathrm{~s}\), doing \(1.2 \mathrm{~J}\) of work on the string in the process. You then allow your hand to...
-
Your job as assistant coach is to attach one end of several heavy, \(10-\mathrm{m}\) ropes to the trusses that support the gym ceiling, leaving the other end of each hanging free. The team is going...
-
You need to insert a metal slab between the two plates of a parallel-plate capacitor. The plates are a distance \(d\) apart, and a battery maintains a constant potential difference \(V_{\text {batt...
-
By what amount was unadjusted revenue overstated in the combined income statement for 20X0? Nolan owns 100 percent of the capital stock of both Twill Corporation and Webb Corporation. Twill purchases...
-
Nobis Company uses an ABC system. Which of the following statements is/are correct with respect to ABC? I. Departmental costing systems are a refinement of ABC systems. II. ABC systems are useful in...
-
On September 1 2 of Year 1 , Rosie Company purchased land, a building, and some equipment for a total price of $ 4 5 0 , 0 0 0 . The land, building, and equipment were appraised at $ 2 4 0 , 0 0 0 ,...
-
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...
-
Assume you want to use random tests on an FIR filter program. How would you know when the program under test is executing correctly?
-
Three devices are attached to a microprocessor: Device 1 has highest priority and device 3 has lowest priority. Each devices interrupt handler takes 5 time units to execute. Show what interrupt...
-
Provide examples of how each of the following can occur in a typical program: a. compulsory miss b. capacity miss c. conflict miss
Study smarter with the SolutionInn App