Java Thing Not Working? [HELP]

Status
This thread has been locked.

Leon

Premium
Feedback score
3
Posts
603
Reactions
160
Resources
0
I made a program for the lols



There's a problem though when I launch the program it asks me the question. When I type something in it displays.

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at base.Input.main(Input.java:11)

Any help??!?!? :)
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Nagi

PM Only - No Skype
Supreme
Feedback score
12
Posts
535
Reactions
679
Resources
0
exCv21462709594krYDI.png

It works though :c
 

Nagi

PM Only - No Skype
Supreme
Feedback score
12
Posts
535
Reactions
679
Resources
0
tryr inputing a different thing than a number. You'll get the exception then. It needs to be parsed and checked if it is a number.
Well yeah, obviously xD but I doubt that he knows exceptions catching though based on the simplicity of that code...
 

Leon

Premium
Feedback score
3
Posts
603
Reactions
160
Resources
0
Got it working, thanks for the help!!!

package base;
import java.util.Scanner;

public class hello {
public static void main (String args[]){
Scanner scan1 = new Scanner(System.in);
System.out.println("Whats Raymond?");
String scan;
String raymond = scan1.nextLine();
System.out.print("Raymond Is A ");
System.out.println(raymond);
}

}
 

ImDaFatBoss

Developer
Premium
Feedback score
0
Posts
55
Reactions
62
Resources
0
You could've easily done this if you're only looking for a double xD

Code:
package base;
import java.util.Scanner;
public class Input {
public static void main (String[] args){
  Scanner userinput = new Scanner(System.in);
  double raymond;
  System.out.println("Whats Raymond?");
  raymond = userinput.nextDouble();
  System.out.println("Raymond Is A");
  System.out.println(raymond + "");

As you can see, adding a ---> "" <--- to it makes it a String, but doesn't effect the final result at all.
 

Leon

Premium
Feedback score
3
Posts
603
Reactions
160
Resources
0
You could've easily done this if you're only looking for a double xD

Code:
package base;
import java.util.Scanner;
public class Input {
public static void main (String[] args){
  Scanner userinput = new Scanner(System.in);
  double raymond;
  System.out.println("Whats Raymond?");
  raymond = userinput.nextDouble();
  System.out.println("Raymond Is A");
  System.out.println(raymond + "");

As you can see, adding a ---> "" <--- to it makes it a String, but doesn't effect the final result at all.

I fixed the problem :)
 
Status
This thread has been locked.
Top