java 实现输出姓和名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
}

  

分类: JAVA
 
 
本文转自左正博客园博客,原文链接: http://www.cnblogs.com/soundcode/p/7122043.html,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值