在循环内访问B“i”变量

时间:2015-11-25 21:06:42

标签: java android loops

我在Android Studio中编写Java,然后在循环中访问不同的B变量。我对语法不太确定。

$query = "
    SELECT * 
    FROM table1 ge 
    INNER JOIN table 2 ad 
    ON ge.ID = ad.ID 
    WHERE ge.ID = ad.ID AND ge.field LIKE '".mysql_real_escape_string($_REQUEST['search'])."%' 
    AND ge.field not like '%".$word. "%' 
    order by ge.field ASC"

3 个答案:

答案 0 :(得分:3)

您无法访问此类变量 您必须定义Listarray

int A = 0;
int[] myIntArray = {1,2,3,4,5};

for (int i = 0; i < myIntArray.length; i++){
    //Now you can access your array with the index
    A = myIntArray[i]; //This statement still does not make much sense
}

您应该阅读一些Java初学者教程,例如this one

答案 1 :(得分:0)

要知道你的意思并不容易,但我会猜测。

int A, B1, B2, B3, B4, B5;

    for (int i = 1; i < 6; i++) {
        switch (i) {
            case 1: A = B1;
                    break;
            case 2: A = B2;
                    break;
            case 3: A = B3;
                    break;
            case 4: A = B4;
                    break;
            case 5: A = B5;
                    break;
            default: break;
        }
        someFunction(A);
    }

我不明白为什么你的循环中有i <= 20。也许我错过了什么。

答案 2 :(得分:0)

我想做什么:P

genotypeselec=function(combinaison,perreur){

  tab <- list()

  for ( i in 1:10){ 

    essai_allele1= genposs[1,i]
    essai_allele2= genposs[2,i]
    nballele1=length(which(combinaison==essai_allele1))
    nballele2=length(which(combinaison==essai_allele2))
    hepallele1=0.5 - perreur/2 + perreur/6
    hepallele2=0.5 - perreur/2 + perreur/6
    hepautresnucs=perreur/3
    hopallele1=1 - perreur
    hopautresnucs=perreur/3


    if (essai_allele1==essai_allele2) {
      #homozygote
      proba_combinaison=(hopallele1**nballele1)* (hopautresnucs**(profondeur-   nballele1))* (factorial(profondeur)/(factorial(nballele1)*(factorial(profondeur-nballele1))))
    }
    else {
      #heterozygote
      proba_combinaison=(hepallele1**nballele1)*(hepallele2**nballele2)* (hepautresnucs**(profondeur-nballele1-nballele2))*(factorial(profondeur)/(factorial(nballele1)*factorial(nballele2)*factorial((profondeur-nballele1-nballele2)))) 
    }
    tab[[length(tab)+1]] <- proba_combinaison
  }

  res <- max(unlist(lapply(tab,FUN=max)))
  names(res) <- c("AA","CC","GG","TT","AC","AG","AT","CG","CT","GT")[which.max(unlist(lapply(tab,FUN=max)))]
  return(res)

}