Error using vectors in Java

3

I have the following line of code calificacion [0] = 3.5,4.2,4.6,5.0,4.5,4.0; I would like to know why I get an error when executing it, I know that it is because of the way it separates the numbers that I put in the vector and they are in double . I do not know which is the correct way to separate the numbers in double . I hope you can help me, thanks. I'm working on Java with vectores .

    
asked by Nahum Deavila 19.05.2016 в 20:29
source

2 answers

2

I do not know if I understand your question too much,

But the declaration of arrays of type double in Java is something like this:

double calificacion [] = {3.5,4.2,4.6,5.0,4.5,4.0};
    
answered by 19.05.2016 в 20:34
0

to fill a vector of type double in java can be like this:

double calificacion[] = {3.5,4.2,4.6,5.0,4.5,4.0};

You can also use a for loop to enter the ratings:

import java.util.Scanner;
public class Arreglo {

public static void main(String args[]){

    Scanner sc = new Scanner(System.in);

    double calificacion[] = new double[6];

    //rutina de ingreso
    for (int i = 0; i < 6; i++) {
        System.out.print("Ingrese numero: ");
        calificacion[i] = sc.nextDouble();
    }//fin for

    //rutina de impresion
    for (int i = 0; i < 6; i++) {
        System.out.println(calificacion[i]);
    }//fin for
   }//fin main           
  }//fin clase
    
answered by 19.05.2016 в 20:50