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

用Java创建数组工具类ArrayTool

起步阶段写的代码,欢迎大家批评指正!

public class ArrayTool
{
	/**
	The constructor of the class ArrayTool,which is empty.
	*/
	private ArrayTool(){}

	/**
	Get the max value of the array.
	@param arr
	@return
	*/
	public static int getMax(int[] arr)
	{
		int max=0;
		for(int x=1;x<arr.length;x++)
		{
			if(arr[x]>arr[max])
				max=x;
		}
		return arr[max];
	}
	
	/**
	Get the min value of the array.
	@param arr
	@return
	*/
	public static int getMin(int[] arr)
	{
		int min=0;
		for(int x=1;x<arr.length;x++)
		{
			if(arr[x]<arr[min])
				min=x;
		}
		return arr[min];
	}

	/**
	Exchange the position of the array element
	@param arr  int type
	@param a
	@param b
	*/
	private static void swap(int[] arr,int a,int b)
	{
		int temp=arr[a];
		  arr[a]=arr[b];
		  arr[b]=temp;
	}

	/**
	Sort the int type array using selectSort
	@param arr 
	*/
	public static void selectSort(int[] arr)
	{
		for(int x=0;x<arr.length-1;x++)
		{
			for(int y=x+1;y<arr.length;y++)
			{
				if(arr[x]>arr[y])
				{
					swap(arr,x,y);
				}
			}
		}
	}


	/**
	Sort the int type array using bubbletSort
	@param arr 
	*/
	public static void bubbleSort(int[] arr)
	{
		for(int x=0;x<arr.length-1;x++)
		{
			for(int y=0;y<arr.length-x-1;y++)
			{
				if(arr[y]>arr[y+1])
				{
					swap(arr,y,y+1);
				}
			}
		}
	}

	/**
	Print out the elements of the array that define
	print style:[element1,element2,...]
	*/
	public static void printArray(int[] arr)
	{
		System.out.print("[");
		for(int x=0;x<arr.length;x++)
		{
			if(x!=arr.length-1)
				System.out.print(arr[x]+",");
			else	
				System.out.print(arr[x]+"]");
		}
		System.out.println();
	}

}


相关文章:

  • 解决实体类噩梦:联合实体类(Java反射+泛型实际应用)
  • proxool数据连接池
  • pdns和powreadmin的安装
  • Jira:必选项设置(创建缺陷、修复缺陷)
  • 如何解读数码相机的直方图
  • CSS3实现的3D按钮精美效果
  • 【零基础学习iOS开发】【01-前言】03-前景和难易度分析
  • OBJEct-c中NSDictionary的用法
  • 数据库设计-主键的设计
  • 移动开发者如何获取免费流量(转载)
  • Aspose.Pdf for Java 4.0 发布
  • 【parser】stanford-parser demo使用
  • 程序环境基于 IO密集 CPU密集考量 SAN NAS 选择的一点建议
  • SQL Server修改标识列方法
  • Uva 10085 - The most distant state
  • ➹使用webpack配置多页面应用(MPA)
  • 2018一半小结一波
  • Codepen 每日精选(2018-3-25)
  • Java面向对象及其三大特征
  • Python实现BT种子转化为磁力链接【实战】
  • ReactNative开发常用的三方模块
  • Wamp集成环境 添加PHP的新版本
  • 从零搭建Koa2 Server
  • 第13期 DApp 榜单 :来,吃我这波安利
  • 分类模型——Logistics Regression
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 可能是历史上最全的CC0版权可以免费商用的图片网站
  • const的用法,特别是用在函数前面与后面的区别
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • #QT项目实战(天气预报)
  • $GOPATH/go.mod exists but should not goland
  • (1)SpringCloud 整合Python
  • (Matalb回归预测)PSO-BP粒子群算法优化BP神经网络的多维回归预测
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (Redis使用系列) Springboot 使用redis实现接口Api限流 十
  • (二)c52学习之旅-简单了解单片机
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (完整代码)R语言中利用SVM-RFE机器学习算法筛选关键因子
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • .NET Micro Framework初体验
  • .NET/C# 使窗口永不获得焦点
  • .net获取当前url各种属性(文件名、参数、域名 等)的方法
  • .net专家(高海东的专栏)
  • :中兴通讯为何成功
  • [ vulhub漏洞复现篇 ] Celery <4.0 Redis未授权访问+Pickle反序列化利用
  • [2019.3.5]BZOJ1934 [Shoi2007]Vote 善意的投票
  • [ARC066F]Contest with Drinks Hard
  • [BZOJ 4129]Haruna’s Breakfast(树上带修改莫队)
  • [BZOJ] 2006: [NOI2010]超级钢琴
  • [C++]AVL树怎么转
  • [C++数据结构](31)哈夫曼树,哈夫曼编码与解码
  • [CF703D]Mishka and Interesting sum/[BZOJ5476]位运算