我必須輸入一個名稱,然後將名稱變成用戶名 如果我輸入布萊恩鋼它必須給我的用戶名BSteel 我可以得到第一個字符沒有的問題,我能找到空間,但能,噸得到鋼的S於自己的,然後以小寫 字的其餘部分,請幫助從第一個和第二個名稱的單一輸入創建用戶名
代碼從OP:
Scanner un = new Scanner(System.in); // declare string
String name;
String firstletter;
String secondletter;
String restofname; //int firstChar =0; // get user input
System.out.println("Enter the users name ");
name = un.nextLine();
firstletter = name.substring(0, 1).toUpperCase(); //char fNc = name.charAt(0);
int position = name.indexOf(" ");
position ++;
嗨,對不起,它是在java到目前爲止我有掃描儀=新掃描儀(System.in); \t \t \t \t //聲明字符串 \t \t字符串名稱; 字符串首字母; String secondletter; String restofname; \t \t // int firstChar = 0; \t \t \t \t //獲取用戶輸入\t \t \t \t的System.out.println( 「請輸入用戶名」); \t \t name = un.nextLine(); \t \t firstletter = name.substring(0,1).toUpperCase(); \t \t \t // char fNc = name.charAt(0); \t \t \t int position = name.indexOf(「」); position ++; – 2014-12-06 14:49:32
不要在評論中放置代碼。它無法格式化,很難找到混亂的地方。您需要[編輯]您的問題以在其中包含信息,併爲您正在使用的語言添加標籤。 – 2014-12-06 14:56:05