Posts

Showing posts with the label java.util.scanner

Using two methods to get multiple user inputs in Java

Image
Clash Royale CLAN TAG #URR8PPP Using two methods to get multiple user inputs in Java I am working on some basic java skills are I am getting a NoSuchElementExemption when I am debugging. My goal is to ask two questions in two different methods and combine them in the main function. Could someone explain the rule that I am breaking? The code is as follows: import java.util.Scanner; public class TwoInputs{ public static double test() { Scanner reader2 = new Scanner(System.in); System.out.println("Enter a number "); double n2 = reader2.nextDouble(); if (n2 %1 != 0) { System.out.println("Number is invalid"); } else { reader2.close(); System.out.println("You put the number " + n2); } return n2; } public static double test2() { Scanner reader1 = new Scanner(System.in); System.out.println("Enter a number "); double n1 = reader1.nex...