在Java中,与JavaScript的console.log()不同,Java没有内置的console.log()函数。但是,您可以使用System.out.println()来实现类似的功能。关于输出格式,Java提供了以下几种常见的格式化方法:
System.out.println()直接输出:System.out.println("Hello, World!");使用System.out.printf()格式化输出:int age = 25;String name = "John";System.out.printf("My name is %s and I am %d years old.", name, age);使用String.format()格式化字符串:int age = 25;String name = "John";String output = String.format("My name is %s and I am %d years old.", name, age);System.out.println(output);使用System.out.format()格式化输出:int age = 25;String name = "John";System.out.format("My name is %s and I am %d years old.\n", name, age);在这些格式化方法中,%s表示字符串,%d表示整数,%f表示浮点数等。您可以根据需要选择合适的格式化方法。


