1. 程式人生 > >2018年12月8日(週末作業11)

2018年12月8日(週末作業11)

依次輸入五句話,然後將它逆序輸出

import java.util.Scanner;
public class 週末課後作業11 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String s = "0";
		System.out.println("請輸入5句話");
		String a[] = new String[5];
		for (int i = 1; i <= a.length; i++) {
			System.out.println("請輸入第" + i + "句話");
			String r = input.next();
			a[i - 1] = r;
		}
		System.out.println("逆序輸出的為");
		for (int c = 0; c < a.length / 2; c++) {
			s = a[c];
			a[c] = a[a.length - 1 - c];
			a[a.length - 1 - c] = s;
		}
		for (String x : a) {
			System.out.println(x);
		}
	}
}