打印类

主要包含字节打印类(PrintStream)字符打印流(PrintWriter).

可以打印任何的数据类型,如小数、整数、字符串等

 

格式化的输出方式,使用printf()方法完成

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

//=================================================
// File Name       :	Print_demo
//------------------------------------------------------------------------------
// Author          :	Common





//主类
//Function        : 	Print_demo
public class Print_demo {

	public static void main(String[] args) throws Exception{
		// TODO 自动生成的方法存根
		PrintStream ps = null;		
		//通过FileOutputStream实例化,意味着所有的输出都是向文件中打印
		ps = new PrintStream(new FileOutputStream(new File("/home/common/software/coding/HelloWord/HelloWord/test.txt")));
		String name = "张三";
		int age = 30;
		float score = 90.123f;
		char sex = 'M';
		
		ps.print("Hello");
		ps.print("Word");
		//格式化输出,字符使用%s,整数使用%d,小数使用%f,字符使用%c
		ps.printf("姓名:%s,年龄:%d,成绩:%f,性别:%c",name,age,score,sex);
		ps.close();
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值