3.数组
发表日期:2015-02-25 21:29:56 | 来源: | | 浏览(738) 分类:JAVA基础
public class ArrayDemo { public static void main(String[] args) { int arr1[] = null;//声明数组 arr1 = new int[9];//为数组开辟9个空间的 大小 //或 int[] arr2 = null; arr2 = new int[9]; //或 int[] arr3 = new int[9]; //或 int arr4[] = new int[9]; arr4[0] = 1;//数组的下标第一位是从0开始的,开辟9个空间,那么最大到8,即0-8 arr4[1] = 2; arr4[2] = 3; arr4[3] = 4; //..... int arr[] = {15,68,84,10,9,20,64,31,3,75,99,21};//数组静态初始化 System.out.println("数组长度"+arr.length);//数组长度12 getMinMax(arr); } public static void getMinMax(int[] arr){ int max = 0; int min = 0; max = min = arr[0]; for (int i = 0; i < arr.length; i++) { if (arr[i]<min) { min = arr[i]; } if (arr[i]>max) { max = arr[i]; } } System.out.println("最小值:"+min);//3 System.out.println("最大值:"+max);//99 } }
ArrayDemo1
import java.util.Arrays; public class ArrayDemo01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int temp[] = {1,5,9,55,65,62,37,7}; Arrays.sort(temp); System.out.println(Arrays.toString(temp));//[1, 5, 7, 9, 37, 55, 62, 65] int point =Arrays.binarySearch(temp, 7);//2 System.out.println(point); Arrays.fill(temp, 7); System.out.println(Arrays.toString(temp));//[7, 7, 7, 7, 7, 7, 7, 7] } }
- JAVA(0)
- JAVA基础(30)
- 1.JAVA开发环境配置(0)
- 2.java数据类型(0)
- 3.数组(0)
- 4.Date(0)
- 5.String 和 StringBuffer类常用方法(0)
- 6.Math类(0)
- 7.Cloneable(0)
- 8.File 文件(0)
- 9.FileReader和FileWriter(0)
- 10.RandomAccessFile(0)
- 11.FileInputStream和FileOutputStream(0)
- 12.InputStreamReader和OutputStreamWriter(0)
- 13.BufferedReader(0)
- 14.Scanner(0)
- 15.DataOutputStream(0)
- 16.Thead 多线程(0)
- 17.TimerTask(0)
- 18.zip(0)
- 19.Charset(0)
- 20.List(0)
- 21.Map(0)
- 22.Properties(0)
- 23.Enumeration(0)
- 24.Collection(0)
- 25.JDBC(0)
- 26.Iterator(0)
- 27.Abstract(0)
- 28.Interface(0)
- 29.Serializable(0)
- 30.Camparable(0)
- JSP基础(50)