當前位置:成語大全網 - 新華字典 - Java程序實驗

Java程序實驗

import java.util.Arrays;

import java.util.Scanner;

public class S {

public static void main(String[] args) {

System.out.println("請輸入壹個身份證號:");

Scanner scanner = new Scanner(System.in);

String id = scanner.nextLine();

String pattern = "44[0-9]{16}";

if(id.matches(pattern)){

System.out.println("廣東");

}else {

System.out.println("非廣東或者非身份證號碼");

}

System.out.println("請輸入字符串:例如AB-C-ABC");

String a1 = scanner.nextLine();

String a2 = a1.replaceAll("A", "First");

String[] a3 = a2.split("-");

System.out.println(Arrays.toString(a3));

System.out.println("請輸入第壹個字符串:");

String b1 = scanner.nextLine();

System.out.println("請輸入第二個字符串:");

String b2 = scanner.nextLine();

if(b1.compareTo(b2) > 0){

System.out.println(b2+"在"+b1+"之前");

}else if(b1.compareTo(b2) < 0) {

System.out.println(b1+"在"+b2+"之前");

}else {

System.out.println("相同");

}

System.out.println("請輸入壹個字符串:");

String str = scanner.nextLine();

String[] ch = str.split("");

System.out.println(ch[1]+ch[2]+ch[3]);

}

}

需要設置中文編碼