Java经典实例:使用ChoiceFormat来格式化复数
2016-11-28 12:05
197 查看
import java.text.ChoiceFormat; /** * Created by Frank */ public class FormatPuralsChoice extends FormatPlurals { static double[] limits = {0, 1, 2}; static String[] formats = {"reviews", "review", "reviews"}; static ChoiceFormat plurlizedFormat = new ChoiceFormat(limits, formats); // 使用ChoiceFormat将数值转换为英语的文本 static ChoiceFormat quantizedFormat = new ChoiceFormat("0#no reviews|1#one review|1<many reviews"); // 测试数据 static int[] data = {-1, 0, 1, 2, 3}; public static void main(String[] args) { System.out.println("Pluralized format"); for (int i : data) { System.out.println("Found " + i + " " + plurlizedFormat.format(i)); } System.out.println("Quantized Format"); for (int i : data) { System.out.println("Found " + quantizedFormat.format(i)); } } } class FormatPlurals { public static void main(String[] args) { report(0); report(1); report(2); } public static void report(int n) { System.out.println("We used" + n + " item" + (n == 1 ? "" : "s")); } }
相关文章推荐
- Java经典实例:使用DateFormatter来格式化日期时间
- JAVA字符串格式化-String.format()的使用
- Java字符串格式化 String。format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化String.format()的使用
- java格式化输出 JAVA String.format 方法使用介绍
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- java 使用simpleDateFormat格式化日期 时间
- java字符串格式化:String.format()方法的使用大全
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA字符串格式化-String.format()的使用
- JAVA中使用format()方法格式化数据(日期转换,货币)
- JAVA字符串格式化-String.format()的使用