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.");         }     } }

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter2: Introduction To Systems Architecture
Section: Chapter Questions
Problem 5VE
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
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
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
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
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage