package practice;
import java.util.Scanner;
public class ReverseOutput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] statement = new String[5];
System.out.println("顺序输入:");
for (int i = 0; i < statement.length; i++) {
System.out.print("请输入第 " + (i + 1) + " 句话:");
statement[i] = sc.next();
}
System.out.println("\n逆序输出:");
for (int i = statement.length - 1; i >= 0; i--) { // 减去1防止数组下标越界
System.out.println("第 " + (i + 1) + " 句话:" + statement[i]);
}
sc.close();
}
}
Java顺序存入五句话逆序输出
最新推荐文章于 2022-03-10 15:57:41 发布