Checks if the number is negative. - Java java.lang

Java examples for java.lang:Math Number

Description

Checks if the number is negative.

Demo Code

/**//  w w  w .  j  av a 2  s .  c  om
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;

public class Main {
    /**
     * Checks if the number is negative.
     * 
     * @param number
     *            The number.
     * @return Returns true if the number is negative otherwise false.
     */
    public static boolean isNegative(int number) {
        return !isPositive(number);
    }

    /**
     * Checks if the number is positive.
     * 
     * @param number
     *            The number.
     * @return Returns true if the number is positive otherwise false.
     */
    public static boolean isPositive(int number) {
        boolean positive = false;
        if (0 < number) {
            positive = true;
        }
        return positive;
    }
}

Related Tutorials