package cn.yang.qian.qian;

import java.util.Arrays;
import java.util.Scanner;

public class yang2 {
	public static void main(String[] args) {
		// 簡答題2 水果
		Scanner input = new Scanner(System.in);
		String[] fruit = new String[5];// 水果陣列
		for (int i = 0; i < fruit.length; i++) {// 迴圈錄入水果
			System.out.println("請輸入第" + (i + 1) + "種水果:");
			fruit[i] = input.next();
		}
		System.out.println("這些水果在字典中出現的順序是:");
		Arrays.sort(fruit);// 用Array類的sort方法進行排序
		for (String s : fruit) {// 迴圈輸出排序後水果
			System.out.println(s);
		}
	}
}

package cn.yang.qian.qian;

import java.util.Scanner;

public class yang3 {
	public static void main(String[] args) {
		// 簡答題3 錄入姓和名
		Scanner input = new Scanner(System.in);
		System.out.println("請輸入任意一個姓名:");
		String name = input.next();
		String familyName = name.substring(1);// 姓
		String lastName = name.substring(0, 1);// 名
		System.out.print("姓氏:" + familyName);
		System.out.println("名字:" + lastName);
	}
}

package cn.yang.qian.qian;

import java.util.Scanner;

public class yang4 {
	public static void main(String[] args) {
		// 簡答題4 查詢字元位置
		Scanner input = new Scanner(System.in);
		System.out.println("請輸入一段字元:");
		String string = input.next();
		System.out.println("請輸入您要查詢的字元:");
		String str = input.next();
		int index = -1;
		do {
			index = string.indexOf(str, index + 1);// 需要查詢的字元 str , 開始查詢的位置 0
			if (index != -1) {
				System.out.println(index);
			}
		} while (index == -1);
	}
}

package cn.yang.qian.qian;

import java.util.Scanner;

public class yang5 {
	public static void main(String[] args) {
		// 簡答題5 對錄入資訊進行有效性驗證
		Scanner input = new Scanner(System.in);
		for (int i = 0; i < 10; i++) {
			System.out.println("請輸入會員生日<月/日:00/00>:");
			String date = input.next();
			if (date.indexOf("/") != 2 || date.length() != 5) {
				System.out.println("生日形式錯誤,請重新輸入");
			} else {
				for (int j = 0; j < 10; j++) {
					System.out.println("請輸入會員密碼:");
					String passWord = input.next();
					if (passWord.length() < 6 || passWord.length() > 10) {
						System.out.println("密碼形式錯誤,請重新輸入");
					} else {
						System.out.println("會員生日是:" + date);
						System.out.println("該會員的密碼是:" + passWord);
						break;
					}
				}
				break;
			}
		}
	}
}

.