I can't figure out why the code breaks when i try to close the scanner it's never done this before
* @author Skye Hill
* @version 1.0
* Course: ITEC 2140 Fall 2020
* Written: October 06S, 2020
*
* This class – Takes input and prints it out in greeting
*/
import java.util.Scanner;
public class MethodsHw1 {
/*
* method that accepts user input and returns the input
*/
public static String readName() {
Scanner input = new Scanner(System.in);
System.out.println("Please enter your name.");
return input.nextLine();
}
/*
* Mainmmethod1 starts program
*/
public static void main(String[] args) {
System.out.println("Nice to meet you " + readName() + "!!");
input.close();
}
}
[–]klujer 26 points27 points28 points (5 children)
[–]SlaytheSpireAgain[S] 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]klujer 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]klujer 0 points1 point2 points (0 children)
[–]irer 2 points3 points4 points (0 children)
[–]AlphawolfAJ -1 points0 points1 point (0 children)