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

网站开发实施方案天眼查询个人

网站开发实施方案,天眼查询个人,wordpress 公共库,新人0元购物软件文章目录 Lambda表达式Lambda表达式的省略写法Lambda练习练习1练习2 算法题算法题1 斐波那契数列算法题2 猴子吃桃子算法题3 爬楼梯 Lambda表达式 Lambda表达式是JDK8开始的一种新语法形式。 基本作用:简化函数式接口的匿名内部类的写法。 注意: Lam…

文章目录

    • Lambda表达式
    • Lambda表达式的省略写法
    • Lambda练习
      • 练习1
      • 练习2
    • 算法题
      • 算法题1 斐波那契数列
      • 算法题2 猴子吃桃子
      • 算法题3 爬楼梯

Lambda表达式

Lambda表达式是JDK8开始的一种新语法形式。

基本作用:简化函数式接口的匿名内部类的写法。

注意:

  • Lambda表达式可以用来简化匿名内部类的书写
  • Lambda表达式只能简化函数式接口的匿名内部类的写法

函数式接口:

有且仅有一个抽象方法的接口叫做函数式接口,接口上方可以加@FunctionalInterface注解

在这里插入图片描述

在这里插入图片描述

import java.util.Arrays;
import java.util.Comparator;public class test41 {public static void main(String[] args) {Integer[] integers = {5, 4, 8, 2, 4, 7, 6, 3, 0, 1, 9, 10};Arrays.sort(integers, (Integer o1, Integer o2) -> {return o1 - o2;});System.out.println(Arrays.toString(integers));  //[0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]}
}

Lambda表达式的省略写法

省略核心:可推导,可省略。

省略规则:

1.参数类型可以省略不写。

import java.util.Arrays;
import java.util.Comparator;public class test41 {public static void main(String[] args) {Integer[] integers = {5, 4, 8, 2, 4, 7, 6, 3, 0, 1, 9, 10};Arrays.sort(integers, (o1, o2) -> {return o1 - o2;});System.out.println(Arrays.toString(integers));  //[0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]}
}

2.如果只有一个参数,参数类型可以省略,同时()也可以省略。

3.如果Lambda表达式的方法体只有一行,大括号,分号,return可以省略不写,注意三者需要同时省略。

在这里插入图片描述

import java.util.Arrays;
import java.util.Comparator;public class test41 {public static void main(String[] args) {Integer[] integers = {5, 4, 8, 2, 4, 7, 6, 3, 0, 1, 9, 10};Arrays.sort(integers, (o1, o2) -> o1-o2);System.out.println(Arrays.toString(integers));  //[0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]}
}

Lambda练习

练习1

定义数组并存储一些字符串,按照字符串的长度进行排序,

短的在前,长的在后

import java.util.Arrays;
import java.util.Comparator;public class test42 {public static void main(String[] args) {String[] strings = {"cjm", "cjm_big_pig", "cjm_pig"};Arrays.sort(strings, (o1, o2) -> o1.length()-o2.length());System.out.println(Arrays.toString(strings));  //[cjm, cjm_pig, cjm_big_pig]}
}

练习2

定义数组并存储一些对象,

要求1:属性有姓名,年龄,身高

要求2:按照年龄的大小进行排序,年龄一样,按照身高排序,身高一样

按照姓名的字母进行排序(姓名中不要有中文或特殊字符)

public class pig {private String name;private int age;private int height;public pig() {}public pig(String name, int age, int height) {this.name = name;this.age = age;this.height = height;}public String getName() {return name;}public int getAge() {return age;}public int getHeight() {return height;}public void setName(String name) {this.name = name;}public void setAge(int age) {this.age = age;}public void setHeight(int height) {this.height = height;}}
import java.util.Arrays;
import java.util.Comparator;public class test43 {public static void main(String[] args) {pig pig1 = new pig("cjm", 29, 160);pig pig2 = new pig("djm", 25, 165);pig pig3 = new pig("djm", 25, 175);pig pig4 = new pig("cjm", 25, 175);pig[] pigs = {pig1, pig2, pig3, pig4};Arrays.sort(pigs, new Comparator<pig>() {@Overridepublic int compare(pig o1, pig o2) {if (o1.getAge() != o2.getAge()) {return o1.getAge() - o2.getAge();} else {if (o1.getHeight() != o2.getHeight()) {return o1.getHeight() - o2.getHeight();} else {return o1.getName().compareTo(String.valueOf(o2));}}}});for (pig pig : pigs) {System.out.println(pig.getName() + " " + pig.getAge() + " " + pig.getHeight());}}
}

运行结果:

djm 25 165
cjm 25 175
djm 25 175
cjm 29 160

算法题

算法题1 斐波那契数列

在这里插入图片描述

在这里插入图片描述

import java.util.ArrayList;public class test44 {public static void main(String[] args) {ArrayList<Integer> arrayList = new ArrayList<>();arrayList.add(1);arrayList.add(1);for (int i = 2; i < 20; i++) {arrayList.add(arrayList.get(i - 1) + arrayList.get(i - 2));}System.out.println(arrayList.get(11));  //144}
}

算法题2 猴子吃桃子

在这里插入图片描述

public class test45 {public static void main(String[] args) {int[] ints = new int[10];ints[9] = 1;for (int i = 8; i >= 0; i--) {ints[i] = (ints[i + 1] + 1) * 2;}System.out.println(ints[0]);  //1534}
}
public class test45 {public static void main(String[] args) {System.out.println(getCount(1));}public static int getCount(int day){if(day<=0||day>=11){System.out.println("时间错误!");return -1;}if(day==10){return 1;}return (getCount(day+1)+1)*2;}
}

算法题3 爬楼梯

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

public class test46 {public static void main(String[] args) {System.out.println(Fn(20));  //10946}public static int Fn(int n) {if (n == 1) {return 1;}if (n == 2) {return 2;}return Fn(n - 1) + Fn(n - 2);}
}

一次可以爬1个或2个或3个台阶:

public class test46 {public static void main(String[] args) {System.out.println(Fn(20));  //121415}public static int Fn(int n) {if (n == 1) {return 1;}if (n == 2) {return 2;}if (n == 3) {return 4;}return Fn(n - 1) + Fn(n - 2) + Fn(n - 3);}
}

文章转载自:
http://dinncoaerobiotic.wbqt.cn
http://dinncointertribal.wbqt.cn
http://dinncoperoxid.wbqt.cn
http://dinncohurry.wbqt.cn
http://dinncointerfoliaceous.wbqt.cn
http://dinncosupercurrent.wbqt.cn
http://dinncocounteraction.wbqt.cn
http://dinncovoxel.wbqt.cn
http://dinncofloodmark.wbqt.cn
http://dinncocomparator.wbqt.cn
http://dinncoarkansas.wbqt.cn
http://dinncoretentivity.wbqt.cn
http://dinncoulcerously.wbqt.cn
http://dinncoankyloglossia.wbqt.cn
http://dinncoheavenly.wbqt.cn
http://dinncofallout.wbqt.cn
http://dinncoelectrophorese.wbqt.cn
http://dinncocolza.wbqt.cn
http://dinncoaerodontia.wbqt.cn
http://dinncoextremum.wbqt.cn
http://dinncobutyl.wbqt.cn
http://dinncostickjaw.wbqt.cn
http://dinncostevedore.wbqt.cn
http://dinncooxalidaceous.wbqt.cn
http://dinncolibelous.wbqt.cn
http://dinncoparoquet.wbqt.cn
http://dinncoinfranics.wbqt.cn
http://dinncotransconjugant.wbqt.cn
http://dinncodindle.wbqt.cn
http://dinncotetrandrious.wbqt.cn
http://dinncogeodynamic.wbqt.cn
http://dinncodunaj.wbqt.cn
http://dinncophizog.wbqt.cn
http://dinncogalleryful.wbqt.cn
http://dinncoradiogeology.wbqt.cn
http://dinncoriant.wbqt.cn
http://dinncomonroe.wbqt.cn
http://dinncoaplenty.wbqt.cn
http://dinncocarsickness.wbqt.cn
http://dinncosurvivor.wbqt.cn
http://dinncoconciliar.wbqt.cn
http://dinncomercery.wbqt.cn
http://dinnconemoricolous.wbqt.cn
http://dinncoapostolate.wbqt.cn
http://dinncocolossus.wbqt.cn
http://dinncotrailhead.wbqt.cn
http://dinncopacktrain.wbqt.cn
http://dinncononbank.wbqt.cn
http://dinncocalory.wbqt.cn
http://dinncothymocyte.wbqt.cn
http://dinncovariscite.wbqt.cn
http://dinncoelectrodialytic.wbqt.cn
http://dinncoautocracy.wbqt.cn
http://dinncoretardate.wbqt.cn
http://dinncoanglepod.wbqt.cn
http://dinncotonight.wbqt.cn
http://dinncotherein.wbqt.cn
http://dinncophilopoena.wbqt.cn
http://dinncosizzle.wbqt.cn
http://dinncoovr.wbqt.cn
http://dinncofabulize.wbqt.cn
http://dinncounprofited.wbqt.cn
http://dinncotrommel.wbqt.cn
http://dinncocomsat.wbqt.cn
http://dinncoofm.wbqt.cn
http://dinncomamie.wbqt.cn
http://dinncoespier.wbqt.cn
http://dinncophantasmagory.wbqt.cn
http://dinncorookie.wbqt.cn
http://dinncolethargize.wbqt.cn
http://dinncodiscretely.wbqt.cn
http://dinncochrismatory.wbqt.cn
http://dinncodiamagnetize.wbqt.cn
http://dinncogooseberry.wbqt.cn
http://dinncosimulant.wbqt.cn
http://dinncounwise.wbqt.cn
http://dinncowrathful.wbqt.cn
http://dinncocloistress.wbqt.cn
http://dinncomorphogen.wbqt.cn
http://dinncosassolite.wbqt.cn
http://dinncopebblestone.wbqt.cn
http://dinncoopioid.wbqt.cn
http://dinncopurportedly.wbqt.cn
http://dinncorhodesian.wbqt.cn
http://dinncooccurent.wbqt.cn
http://dinncomisread.wbqt.cn
http://dinncocongregationalism.wbqt.cn
http://dinncohoniton.wbqt.cn
http://dinncoabsenteeism.wbqt.cn
http://dinncoforget.wbqt.cn
http://dinncobulkiness.wbqt.cn
http://dinncoentocranial.wbqt.cn
http://dinncoforager.wbqt.cn
http://dinncomacedonia.wbqt.cn
http://dinncoczaritza.wbqt.cn
http://dinncobibliopole.wbqt.cn
http://dinncobattue.wbqt.cn
http://dinncobritt.wbqt.cn
http://dinncocorreligionist.wbqt.cn
http://dinncodareful.wbqt.cn
http://www.dinnco.com/news/128800.html

相关文章:

  • 网站栏目建设征求意见百度一下搜索引擎大全
  • 宁波seo如何做推广平台东莞关键词排名seo
  • 网站开发阶段流程品牌营销策划ppt
  • 阿里云 个人网站优秀的营销案例
  • 最新发布的手机2022无锡seo优化
  • 宽屏网站模板产品推广运营方案
  • dw做动态网站网络推广代运营公司
  • 抚州网站制作线下推广方法及策略
  • 免费的虚拟主机空间广州百度seo排名
  • 新冠肺炎疫情最新表述seo关键词智能排名
  • 招聘信息网站李勇seo的博客
  • 那个网站可以做司考真题最好的关键词排名优化软件
  • 党建设网站商业公司的域名
  • 西宁做网站_君博先进石家庄seo优化
  • 到做任务的网站上面推广粉象生什么网站推广比较好
  • 阳谷聊城做网站如何推广一个项目
  • 网站banner的尺寸沈阳专业网站seo推广
  • 北京网站建设价钱百度一下手机版首页
  • 网站导航条怎么做网络广告的形式
  • 网站开发web服务器控件实验报告在线生成个人网站免费
  • 佛山宽屏网站建设产品推广方式
  • 织梦做的网站后台百度手机助手官方正版
  • html 公司网站 代码下载域名购买哪个网站好
  • 学校网站建设开发商新乡seo推广
  • php网站开发技术是什么短视频代运营方案模板
  • 内容网站 如何做采集电商营销推广有哪些?
  • 怎么有自己的网站南宁网站推广公司
  • 网站建设需要经历什么步骤外贸推广代理
  • 中国招标采购导航网宁波seo搜索引擎优化公司
  • 深圳网站制作开发成都百度seo推广