So my question is the following: I get an error on line 12 that I want to solve but haven't found the result for. I use Eclipse to run and write my code.
This is what I do:
- I write absolute
- I enter a number with decimals
an error pops up saying
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 apples.main(apples.java:12)
How come this does not work? Also, I tried running it in CMD outside of Eclipse aswell, without sucess.
import java.util.Scanner;
class apples
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Select one of the following(absolute,ceil,floor,max,min,power,squareroot): ");
String code = scan.nextLine();
if (code.contains("absolute"))
{
System.out.println("Enter a number to get absolute value: ");
Scanner num1 = new Scanner(System.in);
double numberone;
double numberone1 = num1.nextDouble();
System.out.println(Math.abs(numberone1));
}
}
}