Question: Why am I getting this error and how can I solve it? Thanks! I have no error when I use intelliJD but when trying it

Why am I getting this error and how can I solve it? Thanks!

I have no error when I use intelliJD but when trying it in zybooks, I get this error..

Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at ParseStrings.main(ParseStrings.java:27)

My code:

import java.util.Scanner

public class Main { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String userInput = ""; System.out.println("Enter input string:"); userInput = scnr.nextLine(); while (!userInput.equals("q")) { while (userInput.contains(",") == false) { System.out.println("Error: No comma in string"); System.out.println("Enter input string:"); userInput = scnr.nextLine(); } String[] myArray = userInput.split(","); System.out.println("First word: " + myArray[0]); System.out.println("Second word: " + myArray[1]); System.out.println("Enter input string:"); userInput = scnr.nextLine(); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!