7-3 sdut-JAVA -the printf method
分数 10
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
You are required to write a Java application program to produce a report similar to that shown here.
You are expected to use the printf() method when aligning numeric values.
Input Specification:
no input.
Output Specification:
Sample Input:
Sample Output:
Current Assets of ABC Limited
Cash 2100.10
Petty Cash 100.00
Temporary 10000.25
Investments
Accounts receivable 25123.45
Supplies 3800.11
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
public class Main { public static void main(String[] args) { // TODO Auto-generated method stub double a,b,c,d,e; a=2100.10;b=100.00;c=10000.25;d=25123.45;e=3800.11; System.out.println("Current Assets of ABC Limited"); System.out.printf("Cash"+"%24.2f\n",a); System.out.printf("Petty Cash"+"%17.2f\n",b); System.out.printf("Temporary"+"%20.2f\n",c); System.out.println("Investments"); System.out.printf("Accounts receivable"+"%10.2f\n",d); System.out.printf("Supplies"+"%20.2f",e); } }