首页 > 编程知识 正文

java中printwriter用法,java println用法

时间:2023-05-03 07:56:36 阅读:47076 作者:3348

Java printwriter类的println ()方法用于中断的行。 此方法不接受参数或返回值。

使用方法:

公共语音打印机(

参数:此方法不接受参数。

返回:此方法不返回值。

以下方法说明了如何使用println ) )方法。

样本1:

//Java程序到演示

//PrintWriter println () method

import java.io.*;

class GFG {

publicstaticvoidmain (字符串[ ] args ) )。

{

try {

//create a打印机实例

打印机写入器

=new printwriter (系统. out;

//Print the value 'GFG '

//to this stream using print () method

//This will put the in the

//streamtillitisprintedontheconsole

writer.print(gfg );

//Break the line in the stream

//using println () method

writer.println (;

writer.flush (;

}

catch(exceptione ) {

系统. out.println (e;

}

}

}

输出:

GFG

样本2:

//Java程序到演示

//PrintWriter println () method

import java.io.*;

class GFG {

publicstaticvoidmain (字符串[ ] args ) )。

{

try {

//create a打印机实例

打印机写入器

=new printwriter (系统. out;

//Print the value '1.65 '

//to this stream using print () method

//This will put the in the

//streamtillitisprintedontheconsole

writer.print(1.65;

//Break the line in the stream

//using println () method

writer.println (;

writer.flush (;

}

catch(exceptione ) {

系统. out.println (e;

}

}

}

输出:

1.65

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。