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."); } } }
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e135d5c-f867-4afd-9f0d-b505f4f19664%2Fd02b0819-59b4-4233-9193-97924f610405%2Fihfipg_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)