java 实现输出姓和名

发布时间:2017-7-9 7:07:06编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"java 实现输出姓和名 ",主要涉及到java 实现输出姓和名 方面的内容,对于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;


上一篇:设计模式解密(5)- 外观模式(门面模式)
下一篇:百度技术笔记之2013-1

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款