2
import java.util.Scanner;

public class Crescente {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double primo = in.nextDouble();
        double secondo = in.nextDouble();
        double terzo = in.nextDouble();
        if(primo > secondo && primo > terzo) {
            if(secondo > terzo) {
                System.out.println(primo+" "+secondo+" "+terzo);
            }else {
                System.out.println(primo+" "+terzo+" "+secondo);
            }
        }else if(secondo > primo && secondo > terzo) {
            if(primo > terzo) {
                System.out.println(secondo+" "+primo+" "+terzo);
            }else {
                System.out.println(secondo+" "+terzo+" "+primo);
            }
        }else if(terzo > primo && terzo > secondo) {
            if(primo > secondo) {
                System.out.println(terzo+" "+primo+" "+secondo);
            }else {
                System.out.println(terzo+" "+secondo+" "+primo);
            }
        }
        in.close();
    }
}

My program works if you enter integer numbers, but if you enter floating point numbers it gives me this error:

Exception in thread "main" java.util.InputMismatchException
    at java.base/java.util.Scanner.throwFor(Scanner.java:939)
    at java.base/java.util.Scanner.next(Scanner.java:1594)
    at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
    at poo.Crescente.main(Crescente.java:8)

I don't know why it gives me this error since I used nextDouble for all of the variables which are all double. Please help.

user10610048
  • 127
  • 2
  • 8

1 Answers1

1

Looks like your default locale is set to LOCALE.ITALY as you are from Italy. Change it to the following

Scanner in = new Scanner(System.in);
in.useLocale(Locale.ENGLISH);
// rest of the code

I was able to run the program with comma separated numbers (4,2) and decimal separated numbers (4.2) by toggling with the Locale.ITALY and Locale.ENGLISH respectively.

From the doc's :

useLocale(Locale locale)

Sets this scanner's locale to the specified locale.

Nicholas K
  • 15,148
  • 7
  • 31
  • 57