嘿,任何人都可以帮我修复我的deletespherocylinder方法我不知道它有什么问题。 [英] Hey can anyone help me out with fixing my deletespherocylinder method I don't know what is wrong with it.

查看:33
本文介绍了嘿,任何人都可以帮我修复我的deletespherocylinder方法我不知道它有什么问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我现在所拥有的:



 public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder结果= null;
int index = 0; (b i b = b; b< elements; i ++)
{
if(object [i] .getLabel()。equalsIgnoreCase(labelIn))
{
for(int j = i; j< elements - 1; j ++)
{
object [j] = object [j + 1];
}
elements--;
result = object [elements];
休息;
}


}

返回结果;
}





它应该做的是从我的删除(覆盖)一个spherocylinder数组,但是当我提交我的代码进行评分时,出现这个错误:





*方法delete SpherocylinderList类的Spherocylinder:方法没有返回正确删除的spherocylinder。



*类SpherocylinderList的方法deleteSpherocylinder:当使用不同类型的外壳时(例如SmAlL ExAmPle),Method没有返回正确删除的spherocylinder。 />


我运行了我的代码,它完成了所有这一切,运行完美没有任何问题,任何人都可以告诉我,如果我的方法有任何问题,任何帮助将不胜感激。



我尝试了什么:



i试过:



 public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder result = null;
int index = 0; (b i b = b; b< elements; i ++)
{
if(object [i] .getLabel()。equalsIgnoreCase(labelIn))
{
for(int j = i; j< elements - 1; j ++)
{
object [j] = object [j + 1];
result = object [j];
}
object [elements - 1] = null;
elements--;
result = object [elements];
休息;
}


}

返回结果;
}





但它返回null而不是删除(覆盖)数组。到目前为止,下面的代码似乎完全按照我的要求进行,但评分软件不喜欢它,这就是我困惑的地方。





 public Spherocylinder deleteSpherocylinder(String labelIn)
{
Spherocylinder result = null ;
int index = 0; (b i b = b; b< elements; i ++)
{
if(object [i] .getLabel()。equalsIgnoreCase(labelIn))
{
for(int j = i; j< elements - 1; j ++)
{
object [j] = object [j + 1];
// result = object [j];
}
// object [elements - 1] = null;
elements--;
result = object [elements];
休息;
}


}

返回结果;
}

解决方案

使用调试器 - 在行上放置一个断点:

 for(int j = i; j< elements  -  1; j ++)



并从中确切地找出哪个你要删除的元素。然后按照代码找出你要返回的元素。



这很明显是什么问题,为什么 - 如果仔细观察,调试器会告诉你。 / BLOCKQUOTE>

This is what I currently have:

public Spherocylinder deleteSpherocylinder(String labelIn)
{
   Spherocylinder result = null;
   int index = 0;

   for (int i = 0; i < elements; i++)
   {
      if (object[i].getLabel().equalsIgnoreCase(labelIn))
      {
         for (int j = i; j < elements - 1; j++)
         {
            object[j] = object[j + 1];
         }
         elements--;
         result = object[elements];
         break;
      }


   }

   return result;
}



It does what it is supposed to do which is delete(overwrite) a spherocylinder from my array but when I submit my code for a grade this error comes up:


*Method deleteSpherocylinder of class SpherocylinderList: Method did not return the correct deleted spherocylinder.

*Method deleteSpherocylinder of class SpherocylinderList: Method did not return the correct deleted spherocylinder when using different type casing (ex. SmAlL ExAmPle).

I ran my code and It does all of this and runs perfectly with no problem, could anyone please tell me if anything is wrong with my method, any help would be greatly appreciated.

What I have tried:

i tried:

public Spherocylinder deleteSpherocylinder(String labelIn)
{
   Spherocylinder result = null;
   int index = 0;

   for (int i = 0; i < elements; i++)
   {
      if (object[i].getLabel().equalsIgnoreCase(labelIn))
      {
         for (int j = i; j < elements - 1; j++)
         {
            object[j] = object[j + 1];
            result = object[j];
         }
         object[elements - 1] = null;
         elements--;
         result = object[elements];
         break;
      }


   }

   return result;
}



but it returns null instead of the deleted(overwritten) array. So far this code below seems do exactly as I want but the grading software doesn't like it and thats where im confused.


public Spherocylinder deleteSpherocylinder(String labelIn)
{
   Spherocylinder result = null;
   int index = 0;

   for (int i = 0; i < elements; i++)
   {
      if (object[i].getLabel().equalsIgnoreCase(labelIn))
      {
         for (int j = i; j < elements - 1; j++)
         {
            object[j] = object[j + 1];
            //result = object[j];
         }
         //object[elements - 1] = null;
         elements--;
         result = object[elements];
         break;
      }


   }

   return result;
}

解决方案

Use the debugger - put a breakpoint on the line:

for (int j = i; j < elements - 1; j++)


And find out from that exactly which element you are deleting. Then follow the code and find out which element you are returning.

It's pretty obvious what's wrong, and why - and the debugger will show you if you look carefully.


这篇关于嘿,任何人都可以帮我修复我的deletespherocylinder方法我不知道它有什么问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆