Posts

Showing posts with the label user-input

Asking for user input twice in a while loop

Image
Clash Royale CLAN TAG #URR8PPP Asking for user input twice in a while loop I'm currently doing a java project. The project involves a database about NHL Statistics and about accessing bits of information from the database through user input. I'm using a while loop to ask for user input in multiple circumstances, such as asking for the number of penalties received, the number of goals scored, amount of points etc. I am having difficulty with one specific part, it asks the user input for which statistic they want (points, goals, assists,penalties, assists, player, club). After that, if the user types player as their choice, then the system is supposed to ask the user which players statistics they wish to see. The problem is that since I'm using a while loop after the user inputs the first time, the loop is executed and the program ends before the player can input the second time. Any help would be appreciated, here is my code: import java.util.Scanner; import nhlstats.NHLS...

NoSuchElementException in simple User Input loop Java 8 [on hold]

Image
Clash Royale CLAN TAG #URR8PPP NoSuchElementException in simple User Input loop Java 8 [on hold] I've looked around here a lot and haven't found an answer to my problem. I get the exception at "return in13.nextInt()". I've tried a lot of different ways of doing this "play again" thing, that's why right now I have an "int" value for it. I'd be very happy if someone showed me the best way to add this feature to my text game! Edit: This got reported for being "off-topic" because I didn't say what want the code to do, apparently. I want getPlayAgain() to run after game() runs until "user" inputs an integer other than 1. (I'm a beginner at Java) private static Scanner in13; public static void main(String args) { do { game(); } while(getPlayAgain() == 1); in13.close(); } public static int getPlayAgain() { in13 = new Scanner(System.in); ...