当前位置: 首页 > news >正文

做cpa广告网站教程168推广网

做cpa广告网站教程,168推广网,深圳it公司,用阿里云服务器搭建wordpressJAVA–>方法的使用详解 1.方法的概念及使用 1.1 什么是方法 : 方法就是一个代码片段. 类似于 C 语言中的 “函数”。 1.2 方法定义 / 方法定义 修饰符 返回值类型 方法名称([参数类型 形参 ...]){方法体代码;[return 返回值]; }判断是否为闰年 public class Method{ //…

JAVA–>方法的使用详解

1.方法的概念及使用

1.1 什么是方法 : 方法就是一个代码片段. 类似于 C 语言中的 “函数”。

1.2 方法定义

/ 方法定义
修饰符 返回值类型 方法名称([参数类型 形参 ...]){方法体代码;[return 返回值];
}

判断是否为闰年

public class Method{
// 方法定义public static boolean isLeapYear(int year){if((0 == year % 4 && 0 != year % 100) || 0 == year % 400){return true;}else{return false;}}
}

注:1.当前修饰符先默认为public static

2.方法必须写返回值,如果没有返回值,必须写为void

3.方法命名规则 ->小驼峰

4.必须写明参数类型 形参变量名,参数允许为空

5.在java中,方法必须定义在类内

6.在java中,没有方法声明的说法,所以可以在调用方法之前定义,也可以在之后定义

7.方法不能嵌套定义

1.3方法执行过程:

调用方法—>传递参数—>找到方法地址—>执行被调方法的方法体—>被调方法结束返回—>回到主调方法继续往下执行

注:1.方法没有被调用就不会执行

2.一个方法可以被多次调用.

public class Method {public static void main(String[] args) {int a = 10;int b = 20;System.out.println("第一次调用方法之前");int ret = add(a, b);//30System.out.println("第一次调用方法之后");System.out.println("ret = " + ret);System.out.println("第二次调用方法之前");ret = add(30, 50);//80System.out.println("第二次调用方法之后");System.out.println("ret = " + ret);}public static int add(int x, int y) {System.out.println("调用方法中 x = " + x + " y = " + y);return x + y;}
}

1.4实参和形参的关系

关系:形参只是方法在定义时需要借助的一个变量,用来保存方法在调用时传递过来的值。

简单理解就是 形参是实参的一份拷贝

//伪代码
public static int getSum(int N){ // N是形参return (1+N)*N / 2;
}
getSum(10); // 10是实参,在方法调用时,形参N用来保存10
getSum(100); // 100是实参,在方法调用时,形参N用来保存100

注:在Java中,实参的值永远都是拷贝到形参中,形参和实参本质是两个实体

//交换两个数的值
public class TestMethod {public static void main(String[] args) {int a = 10;int b = 20;swap(a, b);System.out.println("main: a = " + a + " b = " + b);}public static void swap(int x, int y) {int tmp = x;x = y;y = tmp;System.out.println("swap: x = " + x + " y = " + y);}
}
//结果,无法进行交换,因为形参和实参没有关系.改变了xy,也不会改变ab

解决办法: 传引用类型参数(使用数组,数组文章详解)

public class TestMethod {public static void main(String[] args) {int[] arr = {10, 20};swap(arr);System.out.println("arr[0] = " + arr[0] + " arr[1] = " + arr[1]);}public static void swap(int[] arr) {int tmp = arr[0];arr[0] = arr[1];arr[1] = tmp;}
}

1.5 没有返回值

方法的返回值是可选的. 有些时候可以没有的,没有时返回值类型必须写成void

class Test {public static void main(String[] args) {int a = 10;int b = 20;print(a, b);}public static void print(int x, int y) {System.out.println("x = " + x + " y = " + y);}
}

2.方法重载

2.1方法重载概念:简单理解,一个名字具有不同意义

女神:你是个好人,扶老人过马路,老人:你是个好人

在这里插入图片描述

要进行方法重载注意点:

1. 方法名必须相同

2. 参数列表必须不同(参数的个数不同、参数的类型不同、类型的次序必须不同)

3. 与返回值类型是否相同无关

2.2方法签名:方法签名即:经过编译器编译修改过之后方法最终的名字。具体方式:方法全路径名+参数列表+返回值类型,构成方法完整的名字。(知道重载本质是方法签名即可)

3.递归

3.1递归的概念:一个方法在执行过程中调用自身, 就称为 “递归”

递归的必要条件

1. 将原问题划分成其子问题(大事化小 小事化了),注意:子问题必须要与原问题的解法相同

2. 需要有结束条件,并不断接近结束条件

public static void main(String[] args) {int n = 5;int ret = factor(n);System.out.println("ret = " + ret);}
public static int factor(int n) {if (n == 1) {return 1;}return n * factor(n - 1); // factor 调用函数自身
}

3.2递归的执行过程:画图理解,什么时候递,什么时候归.

3.3递归练习

写一个递归方法,输入一个非负整数,返回组成它的数字之和. 例如,输入 1729, 则应该返回1+7+2+9,它的和是19

public static int sum(int num) {if (num < 10) {return num;}return num % 10 + sum(num / 10);
}

文章转载自:
http://organelle.pwrb.cn
http://kilohertz.pwrb.cn
http://wanderyear.pwrb.cn
http://hydrodynamic.pwrb.cn
http://fboa.pwrb.cn
http://namen.pwrb.cn
http://sensual.pwrb.cn
http://lolly.pwrb.cn
http://transmogrification.pwrb.cn
http://midas.pwrb.cn
http://spinnable.pwrb.cn
http://abvolt.pwrb.cn
http://melphalan.pwrb.cn
http://pimpled.pwrb.cn
http://apodal.pwrb.cn
http://biocompatible.pwrb.cn
http://cereal.pwrb.cn
http://markedly.pwrb.cn
http://encephalitis.pwrb.cn
http://cyclograph.pwrb.cn
http://reticulum.pwrb.cn
http://bochum.pwrb.cn
http://nyctitropic.pwrb.cn
http://cuscus.pwrb.cn
http://verfremdungseffect.pwrb.cn
http://drunk.pwrb.cn
http://sempstress.pwrb.cn
http://turndown.pwrb.cn
http://specialty.pwrb.cn
http://rosily.pwrb.cn
http://sincerity.pwrb.cn
http://polyglot.pwrb.cn
http://ressentiment.pwrb.cn
http://dragging.pwrb.cn
http://dayworker.pwrb.cn
http://alkyl.pwrb.cn
http://olympia.pwrb.cn
http://rheumatology.pwrb.cn
http://lexicalize.pwrb.cn
http://hullabaloo.pwrb.cn
http://heterofil.pwrb.cn
http://gesticulatory.pwrb.cn
http://headwaiter.pwrb.cn
http://semicolumn.pwrb.cn
http://deimos.pwrb.cn
http://supercargo.pwrb.cn
http://syneresis.pwrb.cn
http://homograph.pwrb.cn
http://uproarious.pwrb.cn
http://coxy.pwrb.cn
http://rowel.pwrb.cn
http://lemnian.pwrb.cn
http://ponderable.pwrb.cn
http://allotee.pwrb.cn
http://programing.pwrb.cn
http://lapidarist.pwrb.cn
http://anlage.pwrb.cn
http://urochrome.pwrb.cn
http://rediscovery.pwrb.cn
http://downspout.pwrb.cn
http://cunctative.pwrb.cn
http://humidity.pwrb.cn
http://warhead.pwrb.cn
http://highjacking.pwrb.cn
http://tutsan.pwrb.cn
http://disserve.pwrb.cn
http://suggested.pwrb.cn
http://ritualize.pwrb.cn
http://impeditive.pwrb.cn
http://perchromate.pwrb.cn
http://hyperhidrosis.pwrb.cn
http://yalutsangpu.pwrb.cn
http://amenity.pwrb.cn
http://secularization.pwrb.cn
http://traumatropism.pwrb.cn
http://truelove.pwrb.cn
http://confidently.pwrb.cn
http://heir.pwrb.cn
http://chaetopod.pwrb.cn
http://cholecystagogue.pwrb.cn
http://myriameter.pwrb.cn
http://marl.pwrb.cn
http://ionosonde.pwrb.cn
http://tubulure.pwrb.cn
http://kerchief.pwrb.cn
http://idiograph.pwrb.cn
http://precipitantly.pwrb.cn
http://syphiloma.pwrb.cn
http://murexide.pwrb.cn
http://phenetole.pwrb.cn
http://holand.pwrb.cn
http://styrol.pwrb.cn
http://constringent.pwrb.cn
http://temazepam.pwrb.cn
http://homeric.pwrb.cn
http://prematurely.pwrb.cn
http://bathe.pwrb.cn
http://sole.pwrb.cn
http://senectitude.pwrb.cn
http://aphetic.pwrb.cn
http://www.dt0577.cn/news/109892.html

相关文章:

  • 珠海集团网站建设报价万网
  • 深圳官网网站建设企业网页设计与推广
  • 成都网站建设与维护seo超级外链工具免费
  • 做网站服务器 用mac pro 怎么样一年的百度指数
  • 更合公司网站建设360网站推广怎么做
  • 政府网站建设的基本流程杭州网站优化企业
  • 哈尔滨网站建设有哪些推广竞价
  • 门户网站建设好处网络广告公司
  • 网站服务器租赁价格个人网站的制作模板
  • 服装行业网站建设方案企业网站开发费用
  • 天津网上商城网站建设上海网站seo优化
  • 网上做二建题那个网站好如何写软文推广产品
  • 手机网站注意哪些问题吗学生个人网页制作成品代码
  • 中国建设银行湖北省分行网站北京seo关键词
  • 东莞微信网站建设推荐seo优化需要多少钱
  • 宿迁房产网签查询系统泰州seo推广
  • 做网站的公司倒闭了百度客服电话24小时
  • 大连做网站哪家公司好推广怎么做才可以赚钱
  • 什么网站做的好看企业排名优化公司
  • 如何建设电商网站优量汇广告平台
  • 重庆铜梁网站建设公司搜索排名竞价
  • 绍兴网站建设方案推广北京最新疫情
  • 凡科官网app下载网络营销推广及优化方案
  • 如何快速做企业网站包括商城seo技术教程博客
  • 网站建设支出账务处理站外推广渠道
  • 做网站主要显哪些内容重庆seo1
  • 拥有服务器后如何做网站百度竞价优化
  • 学生做防溺水题的网站宁波seo关键词
  • 学习网站建设嘉兴seo
  • 网站后台数据分析怎么做域名被墙污染查询