Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code below shows a method that reads positive integers through the keyboard, finds the smallest number, counts its occurrences, and returns the value. If

The code below shows a method that reads positive integers through the keyboard, finds the smallest number, counts its occurrences, and returns the value. If the smallest number appears once or more, it will display the number of occurrences. Assume that the input ends with the number 0 or less, and all necessary libraries have been imported.

However, the method contains at least four (4) errors. Examine the code, and for each error, state the line number where it occurs, state the type of error (syntax, logic/runtime error), and write the exact change or missing code necessary to make the program function as expected.

image

1 public String smallest Number () 2 { 345678 Scanner sc = new Scanner(System.in); System.out.println("Enter numbers (0 or less to exit): "); int number = sc.nextInt(); int smallest = number; int occur = 0; if (number smallest) 9 do 10 { 11 12 { 13 14 15 } 16 17 18 19 20 22 smallest number; occur = 1; else if (number == smallest) occur++; number sc.next(); while (!number.equalsIgnoreCase(0)); if (occur > 0) 21 22 23 { 24 25 222222 26 6780 27 28 } } System.out.println("The smallest number is " + smallest); System.out.println("The occurrence of the smallest number is + number); return smallest;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions