Julio
Julio

Reputation: 1

Java scanner.nextDouble()

Hi I am just learning java with a book; in this, there is an excersise called loan; I am following the sample, but when I want to test the program after I type the loan amount named by me as montoPrestamo (in Spanish) but when I type any value, netBeans does not nothing, no error, no exception, no next prompt, nothing. I dont know what is going on or where is the mistake.

thanks

here is my code:

public static void main(String[] args) {
    double montoPrestamo, interesAnual,pagoMensual,pagoTotal;
    int tiempoPrestamo;      

    Scanner scanner = new Scanner(System.in);

    scanner.useDelimiter(System.getProperty("line.separator"));
    System.out.print("Monto del prestamo (Pesos y Centavos): ");

    montoPrestamo = scanner.nextDouble();

    System.out.print("el valor ingresado es " + montoPrestamo);

    System.out.print("Tasa de Interes anual (ejemplo, 9,5): ");
    interesAnual=scanner.nextDouble();
    System.out.print("Tiempo de periodo del prestamo en años : ");
    tiempoPrestamo=scanner.nextInt();


    System.out.println("");
    System.out.println("Cantidad solicitada $"+montoPrestamo);
    System.out.println("la tasa de interes de su prestamo:"+interesAnual+"%");
    System.out.println("Tiempo del prestamo en años"+tiempoPrestamo);

    System.out.println("\n");
    System.out.println("Pago mensual"+pagoMensual);
    System.out.println("Pago total"+pagoTotal);

}

Upvotes: 0

Views: 267

Answers (1)

Marcus K.
Marcus K.

Reputation: 1040

It works after removing this line:

scanner.useDelimiter(System.getProperty("line.separator"));

Probably this does not work from within an IDE because it uses an own terminal which might use another linefeed separator than your operating system.

Upvotes: 1

Related Questions