tags:

views:

114

answers:

3
import java.util.Scanner;

import java.lang.String;

public class SA3

{

    public static void main(String[] args)
    {


        Scanner scan = new Scanner(System.in);

        System.out.print("Enter student record : ");

        String scores = scan.nextLine();

        String[] StringOfMarks = scores.split(",");
        double[] Marks = new double[StringOfMarks.length];


         for(double i = 0; i < StringOfMarks.length; i++)
         {
             Marks[i] = StringOfMarks[i];
         }
      }

}
A: 

This converts a single array element, not a whole array.

Also, what is the type of Marks? If it's not double[] you're likely to see that "loss of precision" warning.

Oak
it is double ..
WM
@WM: in that case we really need an SSCCE (http://sscce.org/) or at least some more code.
Oak
A: 

This should not affect the precision of your doubles as long as it fits the Java double type. You should also bear in mind, that not every value of double can be represented.

Gabriel Ščerbák
+2  A: 

Change the last part of your code into

for(int i = 0; i < StringOfMarks.length; i++)
{
    Marks[i] = Double.parseDouble(StringOfMarks[i]);
}

You need to use an int typed variable for array element access and need to cast the String explicitly into double.

Timo Westkämper
Also better use variable names starting with a lower case letter which is a convention for Java.
Timo Westkämper