002 - 输出 | Java 笔记
一般输出输出时用加号(“+”)拼接
1. print
print 输出时末尾没有换行:
public class Book
{
public static void main(String args[])
{
System.out.print("I love fishc!");
System.out.print("I love fishc!");
System.out.print("I love fishc!");
System.out.print("pi = " + 3.14);
}
}
效果:
I love fishc!I love fishc!I love fishc!pi = 3.14
2. println
println 输出时末尾有换行:
public class Book
{
public static void main(String args[])
{
System.out.println("I love fishc!");
System.out.println("I love fishc!");
System.out.println("I love fishc!");
System.out.println("pi = " + 3.14);
}
}
效果
I love fishc!
I love fishc!
I love fishc!
pi = 3.14
格式化输出
语法跟 C 很像(可以参考) -> https://fishc.com.cn/forum.php?mod=viewthread&tid=66471
1. printf
public class Book
{
public static void main(String args[])
{
System.out.printf("pi = %.2f\n", 3.14);
System.out.printf("I love %s!\n", "fishc");
System.out.printf("%d %c %d = %d\n", 1, '+', 1, 2);
}
}
效果:
pi = 3.14
I love fishc!
1 + 1 = 2
2. format
public class Book
{
public static void main(String args[])
{
System.out.format("pi = %.2f\n", 3.14);
System.out.format("I love %s!\n", "fishc");
System.out.format("%d %c %d = %d\n", 1, '+', 1, 2);
}
} {:10_256:}前排支持 我心动啦,我要下 Java 楼主的java是在哪里学的?能不能分享一下资源{:10_297:} 小甲鱼的铁粉 发表于 2020-7-6 23:23
楼主的java是在哪里学的?能不能分享一下资源
百度上
和
视频网站上……
页:
[1]