Показаны сообщения с ярлыком Java. Показать все сообщения
Показаны сообщения с ярлыком Java. Показать все сообщения

Члены Java-класса


Разбиение на котроллеры

Как прокомментировать Java-класс

/**
 * Allocates a new <code>String</code> that contains characters from
 * a subarray of the character array argument. The <code>offset</code>
 * argument is the index of the first character of the subarray and
 * the <code>count</code> argument specifies the length of the
 * subarray. The contents of the subarray are copied; subsequent
 * modification of the character array does not affect the newly
 * created string.
 *
 * @param      value    array that is the source of characters.
 * @param      offset   the initial offset.
 * @param      count    the length.
 * @exception  IndexOutOfBoundsException  if the <code>offset</code>
 *               and <code>count</code> arguments index characters outside
 *               the bounds of the <code>value</code> array.
 */
public String(char value[], int offset, int count) {
    if (offset < 0) {
        throw new StringIndexOutOfBoundsException(offset);
    }
    if (count < 0) {
        throw new StringIndexOutOfBoundsException(count);
    }
    // Note: offset or count might be near -1>>>1.
    if (offset > value.length - count) {
        throw new StringIndexOutOfBoundsException(offset + count);
    }

    this.value = new char[count];
    this.count = count;
    System.arraycopy(value, offset, this.value, 0, count);
}


источник

Как оставить в Java-строке только буквы и цифры

Try
return value.replaceAll("[^A-Za-z0-9]", "");
or
return value.replaceAll("[\\W]|_", "");

http://stackoverflow.com/a/1805533/2289640

Как на Java проверить, что строка является палиндромом

    public static Boolean isPalindrome(String s) {
        return s.equals((new StringBuilder(s)).reverse().toString());
    }

Как посчитать факториал на Java

public static BigInteger factorial(int value){
    if(value < 0){
        throw new IllegalArgumentException("Value must be positive");
    }

    BigInteger result = BigInteger.ONE;
    for (int i = 1; i <= value; i++) {
        result = result.multiply(BigInteger.valueOf(i));
    }

    return result;
}

http://stackoverflow.com/questions/891031/is-there-a-method-that-calculates-a-factorial-in-java

Как проверить, является ли число точной степенью двойки

Java
    Scanner in = new Scanner(System.in);
    System.out.print("Enter num: ");
    int n = in.nextInt();
 
    if((n > 0) && ((n & (n - 1)) == 0))
        System.out.println("YES");
    else
        System.out.println("NO");




C++
int isPow2(int a) { return !(a&(a-1)); }

Как в Java инвертировать бит

Шаблоны проектирования Java для начинающих. Бесплатный пошаговый видеокурс с исходными кодами

Применение шаблонов + знания ООП = профессиональный программист. Эта простая формула, но соблюдают ее немногие.

Как работают статические переменные на разных платформах

Сегодня задался вопросом как работают статические переменные на разных платформах, например, на Java VM + JBoss Portal.