集册 Java实例教程 用于定义和调用静态函数的基本演示类

用于定义和调用静态函数的基本演示类

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

436
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
用于定义和调用静态函数的基本演示类
/** 来自 时代Java - nowjava.com**/

public class Main {


  static int square(int x) {

    return x * x;

  }


  static boolean isOdd(int p) {

    if ((p % 2) == 0)

      return false;

    else

      return true;

  }


  static double distance(double x, double y) {

    if (x > y)
    /**
    来 自 n  o  w  j  a  v  a . c o m
    **/

      return x - y;

    else

      return y - x;

  }


  static void display(double x, double y) {

    System.out.println("(" + x + "," + y + ")");

    return; // return void

  }


  public static void main(String[] args) {

    display(3, 2);

    display(square(2), distance(5, 9));


    
展开阅读全文