am trying to run this scanner classes but funny enough,it compiles but throws exception at runtime.What could be the reason?
1.
import java.util.Scanner;
public class ScannerInputer
{
public static void main(String[] kiarie)
{
Scanner wangari=new Scanner(System.in);
double height;
System.out.println("the input is:");
height=wangari.nextDouble();
System.out.println(height);
}
}
this is the output of the first one
the input is:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextDouble(Scanner.java:2387)
at ScannerInputer.main(ScannerInputer.java:10)
2.
import java.util.Scanner;
public class ScannerInputer2
{
public static void main(String[] kiarie)
{
Scanner wangari=new Scanner(System.in);
String height;
System.out.println("enter input :");
height=wangari.nextLine();
System.out.println("your name is:"+height);
}
}
the out put of this one is
enter input :
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at ScannerInputer2.main(ScannerInputer2.java:12)
misbehaving scanner class
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 30 days after creation.
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 30 days after creation.
misbehaving scanner class
Last edited by LockBot on Wed Dec 07, 2022 4:01 am, edited 1 time in total.
Reason: Topic automatically closed 30 days after creation. New replies are no longer allowed.
Reason: Topic automatically closed 30 days after creation. New replies are no longer allowed.
Re: misbehaving scanner class
Thanks Ikey.
Actually i promise not to multi post same problem again.
Actually i promise not to multi post same problem again.
Re: misbehaving scanner class
Back to the same problem of Scanner class,The simple programme dont compiles nicely in Scite but throws exceptions when running it.
When the same is done in Netbeans,it compiles and runs without throwing any exceptions. I think that is very odd.Infact all my programmes with Scanner class
i have to do them in,netbeans.They cant run in Scite.
When the same is done in Netbeans,it compiles and runs without throwing any exceptions. I think that is very odd.Infact all my programmes with Scanner class
i have to do them in,netbeans.They cant run in Scite.