Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

I need help with a java code problem that needs this output shown in image below:

 

import java.util.Scanner;
import java.util.NoSuchElementException;

public class LabProgram {
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);

        int val1 = 0, val2 = 0, val3 = 0; // Initialize the variables
        int max;
        int inputCounter = 0;  // Counter to keep track of the number of inputs read

        try {
            String inputLine = scnr.nextLine();
            String[] parts = inputLine.split(" ");
            
            if (parts.length > 0 && !parts[0].isEmpty()) {
                val1 = Integer.parseInt(parts[0]);
                inputCounter++;
            }
            if (parts.length > 1 && !parts[1].isEmpty()) {
                val2 = Integer.parseInt(parts[1]);
                inputCounter++;
            }
            if (parts.length > 2 && !parts[2].isEmpty()) {
                val3 = Integer.parseInt(parts[2]);
                inputCounter++;
            }

            // If no inputs were provided
            if(inputCounter <= 1 ) {
                throw new NoSuchElementException();
            }

            // Determine the max value
            max = val1;
            if (val2 > max) {
                max = val2;
            }
            if (val3 > max) {
                max = val3;
            }

            System.out.println(max);
        } catch (NoSuchElementException ex) {
            // If exception is caught, check how many inputs were read and print the results
            if (inputCounter == 0) {
                System.out.println("0 input(s) read:\nNo max");
            } else if (inputCounter == 1) {
                System.out.println("1 input(s) read:\nMax is " + val1);
            }
        } catch (NumberFormatException ex) {
            System.out.println("Invalid input. Please provide integers.");
        }
    }
}

 

Input 37
Your output
Expected output
6:Compare output
Input
Output differs. See highlights below. Special character legend
Your output
7
Expected output
2 input (s) read:<
Max is 7
73
7
2 input (s) read:<
Max is 7
expand button
Transcribed Image Text:Input 37 Your output Expected output 6:Compare output Input Output differs. See highlights below. Special character legend Your output 7 Expected output 2 input (s) read:< Max is 7 73 7 2 input (s) read:< Max is 7
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education