• Java 控制台对字符串的处理


    public static void main(String[] args) {
    String rst="";
    List<String> list=new ArrayList<String>();
    List<String> lists=new ArrayList<String>();
    Scanner scanner=new Scanner(System.in);
    String nextLine=scanner.nextLine();
    while (nextLine != null && !nextLine.equals("")) {
    list.add(nextLine);
    nextLine = scanner.nextLine();
    }

    if(list.size()<2){
    System.exit(0);
    }else if(list.size()==2)
    {
    System.out.println(list.get(1));
    }else{
    int count=Integer.valueOf(list.get(0));
    String tmp="";
    int ma[]=new int[list.size()-1];
    int maxcount=0;
    for(int i=1;i<list.size();i++){
    String str=list.get(i);
    String a[]=str.split(",");
    Double len=Math.ceil((double)a.length/count);
    ma[i-1]=len.intValue();
    }
    maxcount=ma[0];
    for(int x =1;x<ma.length;x++){
    if(ma[0]<ma[x]){
    maxcount=ma[x];
    }
    }
    list.remove(0);
    while(maxcount!=0&&list.size()>0){
    maxcount--;
    lists=new ArrayList<String>();
    for(int i=0;i<list.size();i++){
    String str=list.get(i);
    String a[]=str.split(",");
    if(a.length>count){
    tmp="";
    for(int j=0;j<count;j++){
    rst+=a[j]+",";
    }
    for(int j=count;j<a.length;j++){
    tmp+=a[j]+",";
    }
    lists.add(tmp);
    }else{
    for(int j=0;j<a.length;j++){
    rst+=a[j]+",";
    }
    }
    }
    list=lists;
    }
    System.out.println(rst.substring(0,rst.length()-1));
    }

    }
  • 相关阅读:
    Prometheus安装配置
    golang常见错误
    golang数组切片map chan 结构体 初始化
    formdata和xwwwformurlencode的区别
    golang reflect反射
    golang 包之flag包
    golang signal信号处理
    golang import
    golang nil
    golang projectlayout
  • 原文地址:https://www.cnblogs.com/foreverstudy/p/10654581.html
Copyright © 2020-2023  润新知