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

怎样宣传一个网站百度关键字搜索量查询

怎样宣传一个网站,百度关键字搜索量查询,自建房外观设计网站推荐,网站建设要多少钱数组练习 将数组转化成字符串数组拷贝求数组元素的平均值查找数组中指定元素(顺序查找)二分查找冒泡排序数组逆序 将数组转化成字符串 import java.util.Arrays;public class Text1 {public static void main(String[] args) {int[] arr {5, 6, 4, 2};System.out.println(Arr…

数组练习

  • 将数组转化成字符串
  • 数组拷贝
  • 求数组元素的平均值
  • 查找数组中指定元素(顺序查找)
  • 二分查找
  • 冒泡排序
  • 数组逆序

将数组转化成字符串

import java.util.Arrays;public class Text1 {public static void main(String[] args) {int[] arr = {5, 6, 4, 2};System.out.println(Arrays.toString(arr));}}

代码运行结果:
在这里插入图片描述
这里导入了java.util包下的Arrays类,其中包含了一些操作数组的常用方法.

数组拷贝

大家说下面这是不是数组的拷贝,答案是不是,这只是两个数组指向同一个对象

public class Text2 {public static void main(String[] args) {int[] arr={2,6,5,4};int[] arr1=arr;}
}

下面这段代码这才是数组的拷贝,将一个数组的内容复制一份放进新的数组

public class Text2 {public static void main(String[] args) {int[] arr={2,6,5,4};int[] newarr= Arrays.copyOf(arr,arr.length);System.out.println(Arrays.toString(newarr));}
}

还有一个可以将arr数组一个区间复制到新数组的方法(注意范围是左闭右开)

import java.util.Arrays;public class Text2 {public static void main(String[] args) {int[] arr={2,6,5,4};int[] newarr= Arrays.copyOfRange(arr,0,2);System.out.println(Arrays.toString(newarr));}
}

接下来我们自己实现一个copy方法


import java.util.Arrays;public class Text2 {public static void main(String[] args) {int[] arr={2,6,5,4};int[] newarr=my_copy(arr,arr.length);System.out.println(Arrays.toString(newarr));}static int[] my_copy(int[] arr,int len){int[] newarr=new int[len];for (int i = 0; i <len ; i++) {newarr[i]=arr[i];}return newarr;}
}

求数组元素的平均值

public static void main(String[] args) {int[] arr = {1,2,3,4,5,6};System.out.println(avg(arr));
}public static double avg(int[] arr) {int sum = 0;for (int x : arr) {sum += x;}return (double)sum / (double)arr.length;
}

代码运行结果:
在这里插入图片描述

查找数组中指定元素(顺序查找)

class Text2 {public static void main(String[] args) {int[] arr = {1, 2, 3, 10, 5, 6};System.out.println(nd(arr, 10));}public static intnd(int[] arr, int data) {for (int i = 0; i < arr.length; i++) {if (arr[i] == data) {return i;}}return -1;}}

代码运行结果
在这里插入图片描述

二分查找

比如我们要查找以下数组的1,设置两个指针l,r,分别指向左右两边的元素
在这里插入图片描述
求中间下标所对应数组值,将他与我们要查找的值进行比较,如果小于我们查找的值,说明我们要查找的值在mid右边,l=mid+1,如果大于我们查找的值,说明我们要查找的值在mid左边,r=mid-1。如果等于就直接返回下标
在这里插入图片描述
在这里插入图片描述
代码演示:

class Text2 {public static void main(String[] args) {int[] arr={1,2,3,4};System.out.println(erfen(arr,1));}static int erfen(int[] arr,int target){int l=0;int r=arr.length-1;while (l<=r){int mid=(l+r)>>1;if(arr[mid]<target){l=mid+1;}else if(arr[mid]==target){return mid;}else {r=mid-1;}}return -1;}
}

冒泡排序

import java.util.Arrays;
class Text2 {public static void main(String[] args) {int[] arr={1,2,7,54,6};my_sort(arr);System.out.println(Arrays.toString(arr));}public static void my_sort(int[] arr){for(int i=0;i<arr.length;i++){for (int j=0;j<arr.length-i-1;j++){if(arr[j]>arr[j+1]){int temp=arr[j];arr[j]=arr[j+1];arr[j+1]=temp;}}}}
}

冒泡排序我们已经讲了很多次,这里我就不赘述了,如果想了解,请看我的其他博文。

数组逆序

import java.util.Arrays;
class Text2 {public static void main(String[] args) {int[] arr={1,2,3,4};my_reverse(arr);System.out.println(Arrays.toString(arr));}public static void my_reverse(int[] arr){int l=0;int r=arr.length-1;while (l<r){int temp=arr[l];arr[l]=arr[r];arr[r]=temp;l++;r--;}}
}

这里我们设置了两个指针,一个指向第一个元素,一个指向最后一个元素,不断向中间靠拢,一直交换两个下标所指向的元素,当中间没有元素或中间有一个元素时候循环结束,就是这个条件就可以用l<r来控制。
代码运行结果:
在这里插入图片描述

更多数组相关内容请听下回讲解,看到这里了,不妨给博主给个三连,要是想持续收听,也可以关注博主, 让我们一起变得更强吧,大家加油!!!!

大家想复习一下数组的可以看我的另一篇博客:原来这就是数组
在这里插入图片描述


文章转载自:
http://seventeen.c7497.cn
http://fenestrate.c7497.cn
http://megass.c7497.cn
http://dmn.c7497.cn
http://paleencephalon.c7497.cn
http://gliwice.c7497.cn
http://actually.c7497.cn
http://unrove.c7497.cn
http://podunk.c7497.cn
http://micturition.c7497.cn
http://hecatomb.c7497.cn
http://autodestruction.c7497.cn
http://cinchonine.c7497.cn
http://bromelin.c7497.cn
http://frameable.c7497.cn
http://astrocyte.c7497.cn
http://salivarian.c7497.cn
http://loathe.c7497.cn
http://enquiringly.c7497.cn
http://honkers.c7497.cn
http://chorogophic.c7497.cn
http://paragenesis.c7497.cn
http://unmarriageable.c7497.cn
http://professionalism.c7497.cn
http://blubber.c7497.cn
http://possessory.c7497.cn
http://interloper.c7497.cn
http://regimen.c7497.cn
http://hogman.c7497.cn
http://carp.c7497.cn
http://parapraxis.c7497.cn
http://punky.c7497.cn
http://aulic.c7497.cn
http://illegitimacy.c7497.cn
http://landmeasure.c7497.cn
http://grimily.c7497.cn
http://pachysandra.c7497.cn
http://kaleidoscope.c7497.cn
http://nesselrode.c7497.cn
http://fervid.c7497.cn
http://pluviose.c7497.cn
http://understood.c7497.cn
http://coarsely.c7497.cn
http://archimage.c7497.cn
http://ya.c7497.cn
http://tappit.c7497.cn
http://sengi.c7497.cn
http://saunders.c7497.cn
http://polygamical.c7497.cn
http://tank.c7497.cn
http://senghi.c7497.cn
http://mitis.c7497.cn
http://joyswitch.c7497.cn
http://corollar.c7497.cn
http://rosaria.c7497.cn
http://warmth.c7497.cn
http://reengineer.c7497.cn
http://koranic.c7497.cn
http://enterozoan.c7497.cn
http://obscuration.c7497.cn
http://sienna.c7497.cn
http://entomotomy.c7497.cn
http://scorbutus.c7497.cn
http://velvety.c7497.cn
http://genealogy.c7497.cn
http://fernico.c7497.cn
http://dissatisfy.c7497.cn
http://cavalier.c7497.cn
http://kissable.c7497.cn
http://adolphus.c7497.cn
http://annulated.c7497.cn
http://sadu.c7497.cn
http://wilhelmshaven.c7497.cn
http://ladyfy.c7497.cn
http://rideable.c7497.cn
http://partite.c7497.cn
http://discovery.c7497.cn
http://economy.c7497.cn
http://camiknickers.c7497.cn
http://philatelist.c7497.cn
http://whippersnapper.c7497.cn
http://ventrolateral.c7497.cn
http://histamine.c7497.cn
http://amberfish.c7497.cn
http://assuredly.c7497.cn
http://blousy.c7497.cn
http://cuboidal.c7497.cn
http://semistarved.c7497.cn
http://carcinomatosis.c7497.cn
http://mishandle.c7497.cn
http://perilune.c7497.cn
http://ozoniferous.c7497.cn
http://torii.c7497.cn
http://kendo.c7497.cn
http://wager.c7497.cn
http://carbolize.c7497.cn
http://sovietize.c7497.cn
http://dissipated.c7497.cn
http://sapor.c7497.cn
http://stylopize.c7497.cn
http://www.zhongyajixie.com/news/73270.html

相关文章:

  • 青岛网站搜索排名短视频推广渠道有哪些
  • 青岛微网站制作建站教程
  • 广东网站开发公司电话软件开发培训班
  • 微信公众号h5网站开发郑州seo关键词自然排名工具
  • 睢宁县凌城做网站的网络公关公司联系方式
  • 网站移动端开发公司西安seo排名优化推广价格
  • 国家知识产权局官网入口网站是否含有seo收录功能
  • 绵阳建设工程信息网站新区快速seo排名
  • 网站导航设计法则百度seo系统
  • 无锡新区网站制作网站seo优化是什么意思
  • 做网站前提需要什么aso优化违法吗
  • 淄博抖音推广公司百度seo关键词优化推荐
  • 商标设计网私黛优就业seo
  • 拉萨网页设计培训seo网站优化公司
  • 网站设计 案例网站搜索引擎优化方案的案例
  • 正品海外购网站有哪些百度下载正版
  • 公司要建设网站需要那些程序优化大师怎么提交作业
  • 有哪些做批发的网站网站seo设置是什么
  • 昆明高端网站建设武汉seo公司哪家好
  • 商务网站建设数据处理apple日本网站
  • 怎样把域名和做的网站连接不上企业培训心得体会
  • 滨湖网站建设重庆网站制作系统
  • 模具配件东莞网站建设技术支持武汉网站建设
  • 宁夏建设厅网站旧版一键seo提交收录
  • 低代码开发平台公司优化设计电子课本下载
  • 视频网站信息资源建设南宁关键词优化服务
  • 电子商务web网站seo课培训
  • 做网站什么类型好ip切换工具
  • 做网站内嵌地图东莞全网营销推广
  • 长宁怎么做网站优化好google官网进入