马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一般输出
输出时用加号(“+”)拼接
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. printfpublic 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. formatpublic 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);
}
}
|