2
I wrote a simple code in the online java ide (follows code below):
import java.util.Scanner;
public class HelloWorld
{
public static void main(String[] args)
{
String nome = "Filipe";
final double minimo = 15;
Scanner let = new Scanner(System.in);
double n1;
System.out.print("Informe a primeira nota: ");
n1 = let.nextDouble();
double n2;
System.out.print("Informe a segunda nota: ");
n2 = let.nextDouble();
double n3;
System.out.print("Informe a terceira nota: ");
n3 = let.nextDouble();
double n = (n1 + n2 + n3)/3;
System.out.print("A media do aluno " + nome + " e " + n);
if (n < minimo) {
System.out.print("O aluno foi Reprovado");
}
else {
System.out.print("O aluno foi aprovado");
}
}
}
But at the time of compiling in the online ide this occurred:
Informe a primeira nota: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at HelloWorld.main(HelloWorld.java:23)
Can anyone explain to me why?
I’m new to java, so I can’t do anything but something as simple as that --'
– Filipe Teixeira
Where is line 23?
– user28595
Pow dude, line 23 corresponds to n1 = Let.nextDouble(); I saw it here
– Filipe Teixeira
Probably because nothing was typed, see working: http://ideone.com/FYmje4
– Maniero
This, n has how to put some input
– Filipe Teixeira
but how do I use this ideone?
– Filipe Teixeira
The error occurs as @bigown explained, nothing has been typed. Validate the values before comparing them to see if any of them are null.
– user28595
@Filipeteixeira going there and typing a code, choosing the Java language.
– Maniero
vlw ai for help
– Filipe Teixeira