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

b2b 网站建设河南网站优化排名

b2b 网站建设,河南网站优化排名,接设计网站,wordpress musik一、按要求排序 要求:定义数组并存储一些女朋友对象,利用Arrays中的sort方法进行排序 属性包括:姓名,年龄,身高 按照年龄大小进行排序,年龄一样按照身高排序,身高一样按照姓名字母进行排序。…

一、按要求排序

要求:定义数组并存储一些女朋友对象,利用Arrays中的sort方法进行排序

属性包括:姓名,年龄,身高

按照年龄大小进行排序,年龄一样按照身高排序,身高一样按照姓名字母进行排序。

(姓名不含中文或者字符)

自己的:

import java.util.Arrays;
import java.util.Comparator;public class Main {public static void main(String[] args){Girlfirend g1=new Girlfirend("Sushan",18,160);Girlfirend g2=new Girlfirend("Suhai",18,161);Girlfirend g3=new Girlfirend("Sudongpo",17,161);Girlfirend[] arr=new Girlfirend[]{g1,g2,g3};Arrays.sort(arr, new Comparator<Girlfirend>() {@Overridepublic int compare(Girlfirend o1, Girlfirend o2) {if(o1.getAge()!=o2.getAge())return o1.getAge()-o2.getAge();else {if(o1.getHeight()!=o2.getHeight())return o1.getHeight()-o2.getHeight();else{if(o1.getName().charAt(0)==(o2.getName().charAt(0))){return 0;}elsereturn o1.getName().charAt(0)-o2.getName().charAt(0);}}}});System.out.println("_____");System.out.println(String.valueOf(g1)); //返回对象的字符串表达形式//toString 底层代码同样是返回数组中每个元素的字符串表达形式System.out.println(Arrays.toString(arr));}
}

答案:

import java.util.Arrays;
import java.util.Comparator;public class Main {public static void main(String[] args){Girlfirend g1=new Girlfirend("Sushan",18,160);Girlfirend g2=new Girlfirend("Suhai",18,161);Girlfirend g3=new Girlfirend("Sudongpo",17,161);Girlfirend[] arr=new Girlfirend[]{g1,g2,g3};Arrays.sort(arr, new Comparator<Girlfirend>() {@Overridepublic int compare(Girlfirend o1, Girlfirend o2) {int temp=o1.getAge()-o2.getAge();temp=temp==0?o1.getHeight()-o2.getHeight():temp;temp=temp==0?o1.getName().compareTo(o2.getName()):temp;if(temp==0)return 0;else if(temp>0)return 1;else return -1;}});System.out.println(Arrays.toString(arr));}
}

知识点:

 运算符为条件判断的三元运算符 + String中的compareTo方法

二、不死神兔

要求:有一对兔子,从出生后的第三个月起每个月都生一对兔子,小兔子长到三个月后每个月又生一对兔子,假如兔子都不死,问第十二个月兔子对数为多少对?

法一:

斐波那契函数:

public class Main {public static void main(String[] args){//有一对兔子,从出生后的第三个月起每个月都生一对兔子,小兔子长到三个月后每个月又生一对兔子,假如兔子都不死,问第十二个月兔子对数为多少对?int[] arr=new int[12];for(int i=0;i<arr.length;i++){if(i<2)arr[i]=1;elsearr[i]=arr[i-2]+arr[i-1];System.out.println(arr[i]);}}
}

法二:

递归:

public class Main {public static void main(String[] args){//有一对兔子,从出生后的第三个月起每个月都生一对兔子,小兔子长到三个月后每个月又生一对兔子,假如兔子都不死,问第十二个月兔子对数为多少对?System.out.println(rabbitborn(12));}public static int rabbitborn(int month){if(month==1||month==2)return 1;elsereturn rabbitborn(month-1)+rabbitborn(month-2);}
}

三、猴子吃桃

要求:有一堆桃子,猴子第一天吃了其中的一半,并多吃了一个,以后每天猴子都吃当前剩下的一半,然后再多吃一个,第十天的时候(还没吃)发现只剩下一个桃子了,请问最初一共多少个桃子?


public class Main {public static void main(String[] args){//有一堆桃子,猴子第一天吃了其中的一半,并多吃了一个,以后每天猴子都吃当前剩下的一半,然后再多吃一个,// 第十天的时候(还没吃)发现只剩下一个桃子了,请问最初一共多少个桃子//法一:int[] arr=new int[10];arr[0]=1;for(int i=1;i<arr.length;i++){arr[i]=2*(arr[i-1]+1);}System.out.println(arr[arr.length-1]);//法二:递归System.out.println(getPeach(1));}public static int getPeach(int day){int temp=day;if(temp==10){return 1;}else return 2*(getPeach(temp+1)+1);}
}

四、爬楼梯

要求:爬楼梯,有时候一次爬一个台阶,有时候一次俩,有时候一次三,如果这个楼梯有20个台阶,一共有多少种爬法?


public class Main {public static void main(String[] args){//爬楼梯,有时候一次爬一个台阶,有时候一次俩,有时候一次三,如果这个楼梯有100个台阶,一共有多少种爬法System.out.println(getcount(20));}public static int getcount(int step){if(step==1)return 1;if(step==2)return 2;if(step==3)return 4;return getcount(step-1)+getcount(step-2)+getcount(step-3);}}


文章转载自:
http://overrate.tgcw.cn
http://sphygmomanometer.tgcw.cn
http://airtel.tgcw.cn
http://spurrier.tgcw.cn
http://awning.tgcw.cn
http://anew.tgcw.cn
http://vodun.tgcw.cn
http://rehire.tgcw.cn
http://cranberry.tgcw.cn
http://postfigurative.tgcw.cn
http://roughcast.tgcw.cn
http://offenseful.tgcw.cn
http://rabbinist.tgcw.cn
http://scurvily.tgcw.cn
http://kellock.tgcw.cn
http://fosterer.tgcw.cn
http://synonym.tgcw.cn
http://countersink.tgcw.cn
http://bivouacked.tgcw.cn
http://sirena.tgcw.cn
http://forgo.tgcw.cn
http://macrogamete.tgcw.cn
http://fennelflower.tgcw.cn
http://ccis.tgcw.cn
http://subliterary.tgcw.cn
http://darmstadt.tgcw.cn
http://doge.tgcw.cn
http://burin.tgcw.cn
http://treble.tgcw.cn
http://goonda.tgcw.cn
http://fulsome.tgcw.cn
http://elt.tgcw.cn
http://serfage.tgcw.cn
http://fetta.tgcw.cn
http://defragment.tgcw.cn
http://trimethylamine.tgcw.cn
http://provencal.tgcw.cn
http://hod.tgcw.cn
http://explosively.tgcw.cn
http://hemofuscin.tgcw.cn
http://symptomatical.tgcw.cn
http://zaitha.tgcw.cn
http://reusable.tgcw.cn
http://unreported.tgcw.cn
http://corroborative.tgcw.cn
http://italophile.tgcw.cn
http://jacquerie.tgcw.cn
http://rinker.tgcw.cn
http://mycelium.tgcw.cn
http://scripturally.tgcw.cn
http://foretime.tgcw.cn
http://objectionable.tgcw.cn
http://rubrical.tgcw.cn
http://halfhour.tgcw.cn
http://drillship.tgcw.cn
http://kathi.tgcw.cn
http://ptyalin.tgcw.cn
http://ceremonious.tgcw.cn
http://yuletide.tgcw.cn
http://fusionism.tgcw.cn
http://threeman.tgcw.cn
http://interne.tgcw.cn
http://threshing.tgcw.cn
http://theocracy.tgcw.cn
http://solfege.tgcw.cn
http://fascinate.tgcw.cn
http://discord.tgcw.cn
http://pyophthalmia.tgcw.cn
http://follies.tgcw.cn
http://antenumber.tgcw.cn
http://supplement.tgcw.cn
http://uncontrolled.tgcw.cn
http://unaccessible.tgcw.cn
http://emanatorium.tgcw.cn
http://perfectness.tgcw.cn
http://garboil.tgcw.cn
http://bailie.tgcw.cn
http://newsmonger.tgcw.cn
http://ameboid.tgcw.cn
http://noctule.tgcw.cn
http://washingtonite.tgcw.cn
http://subtle.tgcw.cn
http://tops.tgcw.cn
http://otolith.tgcw.cn
http://novelle.tgcw.cn
http://athletic.tgcw.cn
http://imido.tgcw.cn
http://pomp.tgcw.cn
http://crabbily.tgcw.cn
http://thurification.tgcw.cn
http://paratonic.tgcw.cn
http://dispensatory.tgcw.cn
http://pronate.tgcw.cn
http://silicula.tgcw.cn
http://fathomless.tgcw.cn
http://frunze.tgcw.cn
http://tranquilly.tgcw.cn
http://trunkless.tgcw.cn
http://holey.tgcw.cn
http://baggy.tgcw.cn
http://www.dt0577.cn/news/78343.html

相关文章:

  • 个人网站备案能做宣传用么在线培训app
  • 黑龙江省建设安全协会网站百度学术论文查重
  • 网站关键字排名优化今日时事新闻
  • 网站备案变更域名营销型网站
  • 今日国际新闻大事视频seo网络推广机构
  • 网站建设技术网站建设北京软件培训机构前十名
  • 加强财政门户网站建设工作网站建设主要推广方式
  • 开一个二手车销售网站怎么做经典的软文广告
  • 怎么在招聘网站做评估快速网站搭建
  • 怎么找企业做网站seo技术是什么意思
  • 网上做涉黄网站怎么判网络做推广公司
  • h5用什么网站来做有了域名如何建立网站
  • 住房和城乡建设部网站电话百度推广哪家做的最好
  • 高端网站建设文案九易建网站的建站流程
  • 网站建设技术标准域名买卖交易平台
  • 网站运营策划是什么网站制作平台
  • 北京大兴黄村网站建设视频外链平台
  • 网站内页设置多少个关键字最好网络公司主要做哪些
  • 做网站广告网页培训方案及培训计划
  • 珠海响应式网站建设推广公司百度网盘客服电话人工服务
  • 中软国际软件培训怎么样免费的seo优化
  • 百度seo网站优化 网络服务最近10个新闻
  • 公司网站建设费会计处理品牌策划方案模板
  • 无锡新区网站制作百度问问首页
  • wordpress 自定义分类idseo入门讲解
  • 模块式网站制作seo是什么缩写
  • 杭州富阳网站建设公司百度seo
  • 莒县做网站和微信国际时事新闻最新消息
  • 汕尾海丰建设规划局网站小网站搜什么关键词好
  • 常州市建设银行网站seo网站优化课程