_5_12_一维数组

package _5_12_一维数组;

//求一维数组的和

public class _5_123_Exercise_1 {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		int array[]={1,2,3,4,5,6,7,8,9,10};
		System.out.println("数组中元素的和为:");
		int num=0;
		for(int i=0;i<array.length;i++){
			if(i==9)
				System.out.print(array[i]+"=");
			else
				System.out.print(array[i]+"+");
			num+=array[i];
		}
		System.out.println(num);
	}

}
package _5_12_一维数组;

//获取一维数组最小值

public class _5_123_Exercise {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		int array[]={17,82,13,4,5,6,7,8,9,10};
		System.out.println("输出一维数组:");
		int tempMin=array[0];
		for(int i=0;i<array.length;i++){
			if(tempMin>array[i])
				tempMin=array[i];
			System.out.print(array[i]+" ");
			if((i+1)%5==0)
				System.out.println();
		}
		System.out.println("数组最小元素为:"+tempMin);
	}

}

猜你喜欢

转载自jia-shun.iteye.com/blog/2099090