(Answered) I've had some problems with my java code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

10th Oct 2020, 5:21 PM
Hyperion
Hyperion - avatar
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.
10th Oct 2020, 5:36 PM
Coding Cat
Coding Cat - avatar
0
Thanks
10th Oct 2020, 5:37 PM
Hyperion
Hyperion - avatar