-4
我有一個字符串數組,它在第一個單元格中有"lastname,"
。我想刪除" , "
從字符串數組中的字符串末尾刪除「,」
我不想要其他的幫助,只是如何從最後的名字拉出昏迷。
這是送給
1 T T T T T F T T F F
Bobb, Bill 123456789 T T T T T F T T F F
Lou, Mary 974387643 F T T T T F T T F F
Bobb, Sam 213458679 F T F T f t 6 T F f
Bobb, Joe 315274986 t t t t t f t t f f
ZZZZ
輸入這是輸出通緝測驗1 結果:
123-45-6789 Bill Bobb 10
974-38-7643 Mary Lou 9
213-45-8679 Sam Bobb 5
315-27-4986 Joe Bobb 10
The average score is 8.5
這是我
while(!input.equalsIgnoreCase("zzzz")) //while the input is not "zzzz" loop will run
{
String [] key = input.split ("\\s+"); //takes String input and converts it to an array seperated by " "
input = br.readLine();
while(!input.equalsIgnoreCase("zzzz"))
{
String [] student = input.split ("\\s+");//takes in student information seperated by " "
String lname = student[0].substring(0);
String id = student[2].substring(0,3) + "-" + student[2].substring(3,5)+"-"+ student[2].substring(5);//inserts "-" into id#
System.out.println (id);
System.out.println (lname.trim("\,"));
input = br.readLine();
}
}
'String.replaceAll(」, 「」「)'或'簡單地String.substring(0,string.length減() - 1)' – kaetzacoatl
@kaetzacoatl使用'與string.replace ()',除非你需要正則表達式。 – shmosel