集册 Java实例教程 此实用程序方法检查给定数组是否包含任何负值。

此实用程序方法检查给定数组是否包含任何负值。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

395
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
此实用程序方法检查给定数组是否包含任何负值。


//package com.nowjava;


public class Main {/** from n  o  w  j  a  v  a . c o m**/

    public static void main(String[] argv) throws Exception {

        double[] doubleArray = new double[] { 34.45, 35.45, 36.67, 37.78,

                37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };

        System.out.println(isContainNegative(doubleArray));

    }


    /**

     * This utility method checks whether a given array contains any negative

     * value. It returns <tt>true </tt> if it does, <tt>false</tt> if it does

     * not

     * 

     * */

    public static boolean isContainNegative(double[] doubleArray) {

        boolean negativeFound = false;

        int i = 0;

        while (i < doubleArray.length && !negativeFound) {

            if (doubleArray[i] &
展开阅读全文