Java - Scanning comma delimited double and int values
<p>I'm trying to use Java's Scanner class to scan in double and int values delimited by commas.</p>

<p>The following <code>Scanner input = new Scanner(System.in).useDelimiter("\\D");</code> can only scan int values separated by <code>,</code>. e.g. input = <code>1000,2,3</code></p>

<p>How do I scan in double and int values separated by <code>,</code> e.g. input = <code>1000.00,3.25,5</code> or <code>100.00,2,3.5</code>?</p>

<p>I tried the following but they don't seem to work:</p>

<pre><code>Scanner input = new Scanner(System.in).useDelimiter(",");
Scanner input = new Scanner(System.in).useDelimiter("\\,");
Scanner input = new Scanner(System.in).useDelimiter("[,]");
</code></pre>

<p>Using these seems to hang the code. After entering the example input, System.out.println did not execute for the scanned in variables.</p>

<p>Below is my sample code:</p>

<pre><code>import java.io.*;
import java.util.Scanner;

public class Solution {
  public static void main(String args[] ) throws Exception {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    System.out.print("Enter your values: ");
    // Scanner input = new Scanner(System.in).useDelimiter("\\D");
    Scanner input = new Scanner(System.in).useDelimiter(",");
    // Scanner input = new Scanner(System.in).useDelimiter("\\,");
    // Scanner input = new Scanner(System.in).useDelimiter("[,]");

    double investmentAmount = input.nextDouble();
    double monthlyInterestRate = input.nextDouble() / 100 / 12;
    double numberOfYears = input.nextDouble();
    double duration = numberOfYears * 12;

    double futureInvestmentValue = investmentAmount * Math.pow((1 + monthlyInterestRate), duration);
    System.out.println(investmentAmount);
    System.out.println(monthlyInterestRate);
    System.out.println(numberOfYears);
    System.out.println(duration);
    System.out.println("Accumulated value is " + futureInvestmentValue);
  }
}
</code></pre>

<p><strong>Solution found</strong></p>

<p>Updating the Scanner line to the following seem to have fixed it:</p>

<pre><code>Scanner input = new Scanner(System.in).useDelimiter("[,\n]");
</code></pre>