我想“int TAM_ARRAY = Nombre.length();”时出错

时间:2016-10-13 20:45:58

标签: java arrays

所以,我是所有这一切的新手,我想列出我班上所有成员的名单,这标志着我的错误,是的,我在墨西哥学习,所以我有点困惑。任何人都可以帮助我吗?enter code here

package nombres;

import java.util.Arrays;
import java.util.Random;

public class Nombres {

    public static void main(String[] args) {

        String[] Lista;
        String[] Nombre = {"Sebastian", "Jesus", "Lidia", "Ezequiel", "Eli", "Michael", "jaira", "Carlos", "Raul", "Dali", "Javier", "Anabel", "oisa", "Antonio", "Saul", "Carlos", "juis ", "aair", "gfredo", "maron", "fonathan", "barcel", "zlan", "mntonio", "plexander", "mylin"};

        int TAM_ARRAY = Nombre.length();

        Random rand = new Random();

        int posAleatoria = rand.nextInt(TAM_ARRAY - 25);

        String str = Nombre[posAleatoria];

    }

}

1 个答案:

答案 0 :(得分:0)

对于传统的命名方式,请使用Nombre而不是length作为数组名称。 使用length()代替 String[] Lista; String[] nombre = {"Acosta Ochoa Sebastian", "Aguilar Gomez Jesus", "Alejandro Suarez Lidia", "Arevalo Alvarez Ezequiel", "Arias Varela Jair Eli", "Chacon Martinez Michael", "Cordova Contreras Gabriela Yajaira", "Cruz Dominguez Juan Carlos", "Delgado Rodriguez Daniel Raul", "Gallardo Echeverria Isaac Dali", "Gil Bautista Francisco Javier", "Gonzalez Hernandez Anabel", "Lopez Martinez Yesenia Eloisa", "Lopez Pablo Marcos Antonio", "Mendoza Rueda Saul", "Nadal Salaya Juan Carlos", "Ramirez Aguirre Jorge Luis ", "Ramos Ramos Adrian Adair", "Rodriguez Landero Alfredo", "Salaya Cruz Aaron", "Santos Meza Jonathan", "Solis Hernandez Marcel", "Solis Pereyra Alan", "Solis Pereyra Pedro Antonio", "Valencia Salaya Alexander", "Zapata Foster Aylin"}; int TAM_ARRAY = nombre.length; Random rand = new Random(); int posAleatoria = rand.nextInt(TAM_ARRAY)+1;//TAM_ARRAY is the maximum and the 1 is our minimum String str = nombre[posAleatoria]; System.out.println(str); 方法。

__global__ static void CUDAKernelAddOneToVector(int *data){
  const int x  = blockIdx.x * blockDim.x + threadIdx.x;
  const int y  = blockIdx.y * blockDim.y + threadIdx.y;
  const int mx = gridDim.x * blockDim.x;

  data[y * mx + x] = data[y * mx + x] + 1;
}

void AddOneToVector(std::vector<int> &in){
  int *data;
  cudaMallocManaged(reinterpret_cast<void **>(&data),
                    in.size() * sizeof(int),
                    cudaMemAttachGlobal);

  cudaMemcpy(data,in.data(),in.size()*sizeof(int),cudaMemcpyHostToHost);

  dim3 blks(in.size()/(16*32),1);
  dim3 threads(32, 16);

  cudaMemPrefetchAsync(data, in.size() * sizeof(int), 0);

  CUDAKernelAddOneToVector<<<blks, threads>>>(data);

  cudaDeviceSynchronize();

  cudaMemcpy(in.data(),data,in.size()*sizeof(int),cudaMemcpyHostToHost);

  cudaFree(data);
}