Java编程格式输出中 printf 的使用实例

函数运行结果是输出一个表格如下:

Java编程格式输出中 printf 的使用实例

源代码如下:
public class First{
public static void main(String args[]){
System.out.println("Kilograms   Pounds    |     Pounds    Kilograms");
int x;
int y;
for(x=1,y=20;x<=199;x+=2,y+=5){
    double p=2.2*x;
    double k=y/2.2;
    System.out.printf("%-3d         %6.1f    |     %-6d    %9.2f",x,p,y,k);
    System.out.print("\n");
}
}

}
posted @ 2019-03-23 09:31  Kaniso_Vok  阅读(94)  评论(0编辑  收藏  举报