main.java
来自「java的经典例子」· Java 代码 · 共 35 行
JAVA
35 行
import java.text.ChoiceFormat;class Main { static public void main(String[] args) { // Define the integer ranges. double[] limits = {Double.NEGATIVE_INFINITY, 1.0, ChoiceFormat.nextDouble(1.0)}; // Define the strings that map to the ranges. String[] strings = {"Less than one","One","Greater than one"}; // Create a choice format based on the limits and dayName arrays. ChoiceFormat form = new ChoiceFormat(limits, strings); // Diagnostics - print the pattern and nextDouble System.out.println("pattern: " + form.toPattern()); System.out.println("nextDouble(1.0): " + ChoiceFormat.nextDouble(1.0)); // Print a heading. System.out.println("\n" + "num format(num)"); System.out.println("--- -------------"); // Loop over the range, formatting and parsing. for (double num = 0.5; num <= 1.5; num = num + .5) { System.out.print(num + " "); // Format the number and print the resulting string. System.out.println(form.format(num)); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?