Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  

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;

Step by Step Solution

3.48 Rating (164 Votes )

There are 3 Steps involved in it

Step: 1

The execution of the code will be different in both the cases as In first case even if we ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Legal Environment of Business A Critical Thinking Approach

Authors: Nancy K Kubasek, Bartley A Brennan, M Neil Browne

6th Edition

978-0132666688, 132666685, 132664844, 978-0132664844

More Books

Students also viewed these Chemical Engineering questions

Question

Describe the reasons why clinical psychologists perform research.

Answered: 1 week ago