1. 程式人生 > >12.08作業14

12.08作業14

輸入5句話,並且逆序輸出

package javadome3;

import java.util.Scanner;

public class Text {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String [] arr = new String [5];
		System.out.println("請輸入5句話:");
		Scanner input = new Scanner(System.in);
		for(int i = 0;i < arr.
length;i++){ System.out.print("第"+(i+1)+"句話:"); arr[i] = input.next(); } System.out.println("逆向輸出:"); //輸出下標的時候,從0開始!!!! for(int i = arr.length - 1 ;i >= 0;i--){ System.out.println(arr[i]); } } }