Java根据性别随机起名字

import java.util.Random;
import java.util.Scanner;

public class RandomExample {
 Random rd=new Random();
 String name_finamily[]={"张","王","李","赵","刘"};
 String name_man[]={"俊","军","海","涛","威"};
 String name_woman[]={"凌","霞","淑","丹","利"};
 public static void main(String args[]){
  RandomExample r=new RandomExample();
  Scanner scanner=new Scanner(System.in);
  System.out.println("请输入性别:");
  String sex=scanner.next();
  System.out.println(r.Name(sex));
 }
public String  Name(String sex){
  int x[]=new int[2];
     String name;
     for(int j=0;j<2;j++){
  x[j]=(int)(rd.nextFloat()*5);
     }
  if(sex.equals("男")){
   name=name_finamily[x[1]]+name_man[x[0]];
  }
  else if(sex.equals("女")){
   name=name_finamily[x[1]]+name_woman[x[0]];
  }else{

name="请正确输入年龄!";

}
 return name;
}
}

你可能感兴趣的:(Java根据性别随机起名字)