Java程序第七次作业

package assignment;

public class Assignment01 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a = {10, 20, 30, 40, 50};
		for (int n = 0; n < a.length; n++) {
			System.out.println(a[n]);
		}
	}

}

package assignment;

public class Assignment02 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a = new int[5];
		for (int n = 0; n < a.length; n++) {
			a[n] = n;
		}
		for (int n : a) {
			System.out.println(n);
		}
	}

}






package assignment;

public class Assignment03 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		char[] string = {'C', 'h', 'i', 'n', 'a'};
		for (char _ : string) {
			System.out.print(_);
		}
		System.out.println();
	}
}

package assignment;
import java.util.Scanner;

public class Assignment04 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		float[] gradeArray = new float[5];
		Scanner scanner = new Scanner(System.in);
		int n = 0;
		while (n < 5) {
			int grade = scanner.nextInt();
			if (grade < 0 || grade > 100) {
				System.out.println("invalid grade");
				continue;
			}
			gradeArray[n] = grade;
			n++;
		}
		float sum = 0;
		for (float _grade : gradeArray) {
			sum += _grade;
		}
		float average = sum / gradeArray.length;
		System.out.println(sum);
		System.out.println(average);
	}
}

package assignment;

public class Assignment05 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] array = {12, 53, 23, 44, 53};
		for (int n = 0; n < array.length; n++) {
			System.out.println(array[n]);
		}
		for (int n : array) {
			System.out.println(n);
		}
		for (int n = array.length - 1; n >= 0; n--) {
			System.out.println(array[n]);
		
		}
		
	}
}

package assignment;

public class Assignment06 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] array = {0, 1, 2, 3, 4};
		int odd = 0;
		int even = 0;
		for (int n : array) {
			if (n % 2 != 0) {
				odd++;
			}
			else {
				even++;
			}
		}
		System.out.println(odd);
		System.out.println(even);
	}

}

package assignment;

public class Assignment07 {
	public static void main(String[] args) {
		int[] array = new int[100];
		for (int n = 0; n < 100; n++) {
			array[n] = n + 1;
		}
		
		for (int n : array) {
			System.out.println(n);
		}
	}
}

package assignment;

public class Assignment08 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double[] grades = {70, 10, 20, 40, 100, 10, 70, 20, 100};
		for (int n = 0; n < grades.length; n++) {
			double grade = grades[n] + 5;
			if (grade > 100) {
				grade = 100;
			}
			grades[n] = grade;
		}
		
		for (double grade : grades) {
			System.out.println(grade);
		}
	}

}

posted @ 2021-04-20 11:53  SuoJing  阅读(54)  评论(0编辑  收藏  举报