I'm completely new to Java, and I have no idea why it's giving me an error when ran. Can anyone explain to me what's the problem? Tried my best randomly trying different things, but got no where, and I'll probably learn more from someone who knows what they're doing. Thank you!
My codes:
import java.util.Scanner;
// Get date input and display results
// Parse using a delimiter
public class InputOutput3
{
public static void main(String[] args)
{
// Declare variables
String dateIn, input;
int month, day, year;
Scanner scan, scann;
// Initialize variables
scan = new Scanner(System.in);
// Prompt and wait for input
System.out.print("Enter enter the date (mm/dd/yy) > ");
dateIn = scan.nextLine();
scan.close();
// Analyze value entered
scan = new Scanner(dateIn);
scan.useDelimiter("/");
month = scan.nextInt();
day = scan.nextInt();
year = scan.nextInt();
// Display results
System.out.println("The month is " + month);
System.out.println("The day is " + day);
System.out.println("The year is " + year);
//Get their name
scann = new Scanner(System.in);
System.out.print("Please enter your name: ");
input = scann.nextLine();
System.out.print("Your name is " +input);
// Close resources
scan.close();
scann.close();
}
}
Results:
Please enter your name:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at InputOutput3.main(InputOutput3.java:38)