// strings/Conversion.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.math.*;import java.util.*;public class Conversion {public static void main(String[] args) {Formatter f = new Formatter(System.out);char u = 'a';System.out.println("u = 'a'");f.format("s: %s%n", u);// f.format("d: %d%n", u);f.format("c: %c%n", u);f.format("b: %b%n", u);// f.format("f: %f%n", u);// f.format("e: %e%n", u);// f.format("x: %x%n", u);f.format("h: %h%n", u);int v = 121;System.out.println("v = 121");f.format("d: %d%n", v);f.format("c: %c%n", v);f.format("b: %b%n", v);f.format("s: %s%n", v);// f.format("f: %f%n", v);// f.format("e: %e%n", v);f.format("x: %x%n", v);f.format("h: %h%n", v);BigInteger w = new BigInteger("50000000000000");System.out.println("w = new BigInteger(\"50000000000000\")");f.format("d: %d%n", w);// f.format("c: %c%n", w);f.format("b: %b%n", w);f.format("s: %s%n", w);// f.format("f: %f%n", w);// f.format("e: %e%n", w);f.format("x: %x%n", w);f.format("h: %h%n", w);double x = 179.543;System.out.println("x = 179.543");// f.format("d: %d%n", x);// f.format("c: %c%n", x);f.format("b: %b%n", x);f.format("s: %s%n", x);f.format("f: %f%n", x);f.format("e: %e%n", x);// f.format("x: %x%n", x);f.format("h: %h%n", x);Conversion y = new Conversion();System.out.println("y = new Conversion()");// f.format("d: %d%n", y);// f.format("c: %c%n", y);f.format("b: %b%n", y);f.format("s: %s%n", y);// f.format("f: %f%n", y);// f.format("e: %e%n", y);// f.format("x: %x%n", y);f.format("h: %h%n", y);boolean z = false;System.out.println("z = false");// f.format("d: %d%n", z);// f.format("c: %c%n", z);f.format("b: %b%n", z);f.format("s: %s%n", z);// f.format("f: %f%n", z);// f.format("e: %e%n", z);// f.format("x: %x%n", z);f.format("h: %h%n", z);}}/* Output:u = 'a's: ac: ab: trueh: 61v = 121d: 121c: yb: trues: 121x: 79h: 79w = new BigInteger("50000000000000")d: 50000000000000b: trues: 50000000000000x: 2d79883d2000h: 8842a1a7x = 179.543b: trues: 179.543f: 179.543000e: 1.795430e+02h: 1ef462cy = new Conversion()b: trues: Conversion@15db9742h: 15db9742z = falseb: falses: falseh: 4d5*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。