0
(Answered) I've had some problems with my java code
This is my code: import java.util.Scanner; public class Program { public static void main(String[] arg) { Scanner num = new Scanner(System.in); Scanner var = new Scanner(System.in); if ((num.nextInt() * 0.02) < var.nextInt()) { System.out.println("Pesos"); } else if ((num.nextInt() * 0.02) > var.nextInt()) { System.out.println("Dollars"); } } } Whenever it runs I get this error: Exception in thread main, java.util.noSuchElementException Please help.
2 Answers
0
Put your Scanner results in variables. For example:
int a = num.nextInt();
int b = var.nextInt() ;
With every call of nextInt() method, the Scanner want read the next Element. But you have only two.
0
Thanks