0

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);

}
khelwood
  • 46,621
  • 12
  • 59
  • 83
Julio
  • 1
  • 2
  • I don't have NetBeans, but I'd avoid setting the delimiter as the system-dependant line.separator property. IDE consoles tend to treat end of lines as just "\n", regarldess on whether you're on Windows or elsewhere. – kumesana May 11 '18 at 09:44
  • 1
    Possible duplicate of [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – azro May 11 '18 at 09:46
  • @azro nah. The code clearly isn't in that case – kumesana May 11 '18 at 11:35

1 Answers1

1

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.

Marcus K.
  • 805
  • 9
  • 24
  • If you remove it, though, by default Scanner accepts any whitespace as separator. That's not keeping the original intent of usage of Scanner. – kumesana May 11 '18 at 11:37
  • thanks Marcus K and Kumesana, it was truth, it seems to be (line.separator) is used when the SO is mac, it does not work on Windows. Thanks from Colombia – Julio May 13 '18 at 00:26