从字符串数组中的字符串末尾删除“,”

时间:2017-02-28 00:06:18

标签: java arrays

我有一个在第一个单元格中有"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 ();
      }
  }

1 个答案:

答案 0 :(得分:0)

而(!input.equalsIgnoreCase( “ZZZZ”))           {             String [] student = input.split(“\ s +”); //接收由“”分隔的学生信息             String lname = student [0] .substring(0,student [0] .length() - 1); //从姓氏中删除“,”。             String fname = student [1];             String id = student [2] .substring(0,3)+“ - ”+ student [2] .substring(3,5)+“ - ”+ student [2] .substring(5); // insert“ - “进入id#

        int score =0;
        int i =1;
        while(i<=key.length-1)
          {
            if(key[i].equalsIgnoreCase(student[i+2]))
            {
              score++;
              i++;
            }
            else
              i++;

          tscore += score;
          scount++;
          }
        if(scount == 0)
            System.out.println ("Empty class data");

        System.out.println(scount);
        System.out.println ("Results for quiz " + key[0] + ":" +'\n');    
        System.out.println (id + " " +fname+ " "+lname+" "+score);
        System.out.println(key[1] +":"+student[3]);
        input = br.readLine ();
      }