在Java中用括号格式化负数输出
可以使用Formatter对象显示负数输出-
Formatter f = new Formatter();
f.format("%12.2f", -7.598);
System.out.println(f);尝试以下给定的代码来格式化带括号的负数输出-
Formatter f = new Formatter();
f.format("%(d", -50);
System.out.println(f);以下是一个例子-
示例
import java.util.Formatter;
public class Demo {
public static void main(String args[]) {
Formatter f = new Formatter();
f.format("% d", 50);
System.out.println(f);
//括号内的负数
f = new Formatter();
f.format("%(d", -50);
System.out.println(f);
}
}输出结果
50 (50)
热门推荐
10 小红书生日祝福语简短
11 拜新年的祝福语简短
12 祝福语同事离职英文简短
13 新人结婚父母祝福语简短
14 给新年祝福语简短独特
15 幸福卡片祝福语英文简短
16 财运健康成语祝福语简短
17 简短古文生日祝福语
18 宝宝新年祝福语大全简短