java 实现输出姓和名

package xiaojie;
import java.util.Scanner;
public class baiJiaXing {
public static void main(String[] args){
System.out.println("请输入名字:");
Scanner sc=new Scanner(System.in);
String name=sc.next();
String[] bai={"欧阳","太史","上官","端木","司马","东方","独孤","南宫","万俟","闻人","夏侯","诸葛","尉迟","公羊","赫连","澹台","皇甫","宗政","濮阳","公冶","太叔","申屠","公孙","慕容","仲孙","钟离","长孙","宇文","司徒","鲜于","司空","闾丘","子车","亓官","司寇","巫马","公西","颛孙","壤驷","公良","漆雕","乐正","宰父","谷梁","拓跋","夹谷","轩辕","令狐","段干","百里","呼延","东郭","南门","羊舌","微生","公户","公玉","公仪","梁丘","公仲","公上","公门","公山","公坚","左丘","公伯","西门","公祖","第五","公乘","贯丘","公皙","南荣","东里","东宫","仲长","子书","子桑","即墨","达奚","褚师","吴铭"};
String name1=name.substring(0,2);
boolean flag = false;
for (int i = 0; i < bai.length; i++) {
if (name1.equals(bai[i])) {
flag = true;
System.out.println("姓:" + name1);
System.out.println("名:" + name.substring(2));
break;
}
}
if (!flag) {
System.out.println("姓:" + name.charAt(0));
System.out.println("名:" + name.substring(1));
// break;
}

  

posted @ 2017-07-05 16:21  左正  阅读(3593)  评论(0编辑  收藏  举报