+ 1

some one could explain why this don wanna run.

Code: import java.util.Scanner; class Comparison { public static void main(String[] args) { Scanner z = new Scanner(System.in); Scanner x = new Scanner(System.in); Scanner y = new Scanner(System.in); System.out.println(" Maximum number you input: "); System.out.println(max1(z.nextDouble(),x.nextDouble(),y.nextDouble())); System.out.println(" Minimum number you input: "); System.out.println(min2(z.nextDouble(),x.nextDouble(),y.nextDouble())); } static double max1(double x, double y, double z){ if (x>y && x>z){ return x; } else if (y>z){ return y; } else { return z; } } static double min2(double x, double y, double z){ if (x<y && x<z){ return x; } else if (y<z){ return y; } else { return z; } } } output: Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextDouble(Unknown Source) at Comparison.main(Comparison.java:9)

25th Apr 2017, 8:42 AM
MKey
MKey - avatar
2 odpowiedzi
+ 12
If you tested that at the code playground, it didn't run because you created three new Scanner objects. You need only one and than take all the inputs with that one Scanner object. Keep in mind that you have to input all six values at the one input prompt that shows up when you run your program. So you have to input six double values, each in one line, separated by line break.
25th Apr 2017, 10:37 AM
Tashi N
Tashi N - avatar
+ 2
@Tashi N thx alot now its working :)
25th Apr 2017, 11:31 AM
MKey
MKey - avatar