return 的用法

return 语句可以放在方法的任何一个位置

可以放在while{}也可以放在if{}中,没有限制

 如果返回值是void,也可以直接终结函数。

  例如:

  public boolean check(int[]  a)

  { 

   for (int i = 0; i < n; i++)

    {

      sum += a[i];

      if (sum > 100)

        return true;

    }

    return false;

  }

   

原文地址:https://www.cnblogs.com/yangwu-183/p/10193420.html