Java printf formatting to print items in a table or columns

前端 未结 4 640
你的背包
你的背包 2021-01-19 17:24

I am wanting to print things in a neat columns using printf.

happening       0.083333    [4]
hi              0.083333    [0]
if              0.083333    [8]
         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 18:07

    System.out.format("%-8s%-8s%-8s\n","a","b","pow(b,a)");
    System.out.format("%-8d%-8d%-8d\n",1,2,1);
    System.out.format("%-8d%-8d%-8d\n",2,3,8);
    System.out.format("%-8d%-8d%-8d\n",3,4,81);
    System.out.format("%-8d%-8d%-8d\n",4,5,1024);
    System.out.format("%-8d%-8d%-8d\n",5,6,15625);
    
    //the negative integer kinda sets it back to the number of space needed
    

提交回复
热议问题