Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从字符串数组中的字符串末尾删除“,”_Java_Arrays - Fatal编程技术网

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

Java 从字符串数组中的字符串末尾删除“,”,java,arrays,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

我有一个字符串数组,在第一个单元格中有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 ();
      }
  }

一会儿!input.equalSignoreCasezz { 字符串[]student=input.split\s+;//接收由分隔的学生信息 字符串lname=student[0]。子字符串0,student[0]。长度-1;//从姓氏中删除。 字符串fname=student[1]; 字符串id=student[2]。子字符串0,3+-+student[2]。子字符串3,5+-+student[2]。子字符串5;//将-插入到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 ();
      }
String.replaceAll、或干脆String.substring0、String.length-1@kaetzacoatl除非需要正则表达式,否则请使用String.replace。