我一直在玩 printf 方法,但我对这段代码的输出感到困惑:
public static void main(String[] args) {
String[] names = {"Sam, John, George"};
double[] balances = {1000.97,100.00,87.00};
for(int i=0; i<names.length; i++){
System.out.printf("Hello %s this is your balance %.2f\n",names[i],balances[i]);
}
}
The output: Hello Sam, John, George this is your balance 1000.97
Run Code Online (Sandbox Code Playgroud)
我希望每个人在控制台中都有三个打印语句。
感谢您的帮助。
"Sam, John, George" 是一个字符串。
你缺少一些引号。它应该是:
String[] names = {"Sam", "John", "George"};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
80 次 |
| 最近记录: |