【问题标题】:Error: Syntax error on token(s), misplaced construct(s) on my array code错误:令牌上的语法错误,我的数组代码上的构造错误
【发布时间】:2014-09-30 23:55:12
【问题描述】:

我正在学习编程,我正在研究数组,但是在这个方法(它在一个类中)中,由于某种原因,当它编译时它向我显示“错误:令牌上的语法错误,错误的构造( s)”消息。

这是代码:

    public int[] ByN(int[] vector){
      int Blancas = 0;
      int Negras = 0;
      int[] ByN = new int[2];
      combinacion temporal = new combinacion(tamlog);

      temporal.copiar(vec);

      for (int i = 0; i < tamfisico; i++){
        int j = 0;
        Boolean Tof=false;

        While ((ToF == false) && (j < tamfisico);){
          if (vector[i] == temporal[j]){
             Blancas ++;
             temporal.borrar(j);
             j--;
             t--;
             ToF= true;
          }
          j++;
         }
      }


      for (int i = 0; i < tamlog; i++){
        if (vec[i]== vector[i])
          Negras++;
     }
      Blancas = Blancas - Negras;
      ByN[0]= Blancas;
      ByN[1] = Negras;
      return ByN;
     }

这意味着考虑 2 个 int 数组并计算两个数组中有多少 - 有多少在完全相同的位置。

问题似乎出在第一个不知道为什么...

【问题讨论】:

    标签: java arrays


    【解决方案1】:

    改变

    While ((ToF == false) && (j < tamfisico);){
    

    while ((ToF == false) && (j < tamfisico)){
    

    (小写while,没有分号)

    【讨论】:

      【解决方案2】:

      当我浏览您的代码时,我发现了您所犯的以下错误。 Java 正在使用“camelCase”命名转换模式。

      1. 变量的第一个字母不能是大写字母

        int 布兰卡斯 = 0; -----> 内部平衡

        int 内格拉斯 = 0; -----> int negras

      2. 方法的首字母不能大写

        public int[] ByN(int[] vector) -----> public int[] byN(int[] vector)

      3. 类的第一个字母应该是大写字母

        组合时间 = 新组合(tamlog); -----> Combinacion temporal = new Combinacion(tamlog);

      4. “While”字的起始字母应该像“while”一样简单

      另外,

      " While ((ToF == false) && (j

      替换“w”字母并删除;来自声明。

      祝你好运!!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-24
        • 1970-01-01
        • 2013-05-20
        • 1970-01-01
        • 1970-01-01
        • 2013-07-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多