JAVA...谢谢!谢谢!

2024-11-18 02:49:54
推荐回答(2个)
回答1:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package structor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;

/**
*
* @author Administrator
*/
public class ProAccount {

public static void main(String[] args) throws IOException {
while (true) {//实现循环输入
ProAccount pa = new ProAccount();
String name;
String surname;
String rt;
StringBuffer str = new StringBuffer("");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入名(字母): \n");
name = br.readLine();
System.out.print("请输入姓(字母): \n");
surname = br.readLine();
while (!pa.Islength(surname)) {
System.out.print("超过5位.请重新输入: \n");
surname = br.readLine();
}
if (pa.Islength(surname)) {
rt = pa.getStr(surname, str, name);//调用函数获得结果
System.out.print("结果是:"+rt + "\n");
}
}
}
boolean Islength(String sur) {//判断姓的字母个数是否超过5
if (sur.length() > 0 && sur.length() <= 5) {
return true;
}
return false;
}
int getNum()//获得10到99的数字
{
int num = 0;
num = (int) (new Random()).nextInt(90)+10;//0<=num<100的整数
return num;
}
String getStr(String sur, StringBuffer str, String name) {//获得需要的字符串
ProAccount pa = new ProAccount();
String result = "";
if (pa.Islength(sur)) {
int num = pa.getNum();
str = str.append(num);
result = name.charAt(0) + sur + str;
return result;
}
return result;
}
}

回答2: