English 中文(简体)
如何找到一个比另一个要素少的内容?
原标题:How do find a element that is less then another element?

I m 试图建立一个用扼杀而不是ger器的宾平搜索方案。 问题在于,我不知道如何使数量少而少,这样就显得微不足道。

例如

阵列的阵列少于扼杀值。

/**
   The StringBinarySearcher class provides a public static
   method for performing a binary search on an String array.
*/



public class StringBinarySearcher
{
   /**
      The search method performs a binary search on an String
      array. The array is searched for the number passed to
      value. If the number is found, its array subscript is
      returned. Otherwise, -1 is returned indicating the
      value was not found in the array.
      @param numbers The array to search.
      @param value The value to search for.
   */



   public static int search(String[] numbers, String value)
   {
      int first;       // First array element
      int last;        // Last array element
      int middle;      // Mid point of search
      int position;    // Position of search value
      boolean found;   // Flag

      // Set the inital values.
      first = 0;
      last = numbers.length - 1;
      position = -1;
      found = false;

      // Search for the value.
      while (!found && first <= last)
      {
         // Calculate mid point
         middle = (first + last) / 2;

         // If value is found at midpoint...
         if (numbers[middle] == value)
         {
            found = true;
            position = middle;
         }

         // else if value is in lower half...
         // needs array to be less then the string value?, without using equality regulators
         else if (numbers[middle].compareTo(numbers[middle +1]) > 0)
            last = middle - 1;
         // else if value is in upper half....
         else
            first = middle + 1;
      }

      // Return the position of the item, or -1
      // if it was not found.
      return position;
   }
}
最佳回答
问题回答

你的问题是比较操作员(=)。 比较操作者仅对 Java的原始数据类型作了明确界定。 浏览是一种类别(不是原始数据类型)。 因此,您将需要使用“Sting s>codequalitys(String)方法加以比较。

If you want to compare them as numbers, then you will need to parse them into Integers. For this, you can use Integer.parseInt(String) and then compare the Integers.

对于原始数据类型,这种工程是罚款的。 不是用于 Str。

= 用于检查两个物体的参照点是否相同。

String strName1 = "Me";
String strName2 = new String("Me");

strName1 == strName2 is false. Since they are referring to two different objects.

你们可以采用平等的方法进行比较。

if (strName2 .equals(strName2 )) {
    System.out.println("Me and Me are same :P");
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签