zl程序教程

您现在的位置是:首页 >  后端

当前栏目

在java中print和println_JAVA命令行参数

JAVA命令行 参数 PRINT println
2023-06-13 09:11:12 时间

大家好,又见面了,我是你们的朋友全栈君。

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

用法:

public void println()

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

返回:此方法不返回任何值。

下面的方法说明了println()方法的用法方式:

示例1:

// Java program to demonstrate

// PrintWriter println() method

import java.io.*;

class GFG {

public static void main(String[] args)

{

try {

// Create a PrintWriter instance

PrintWriter writer

= new PrintWriter(System.out);

// Print the value ‘GFG’

// to this stream using print() method

// This will put the in the

// stream till it is printed on the console

writer.print(“GFG”);

// Break the line in the stream

// using println() method

writer.println();

writer.flush();

}

catch (Exception e) {

System.out.println(e);

}

}

}

输出:

GFG

示例2:

// Java program to demonstrate

// PrintWriter println() method

import java.io.*;

class GFG {

public static void main(String[] args)

{

try {

// Create a PrintWriter instance

PrintWriter writer

= new PrintWriter(System.out);

// Print the value ‘1.65’

// to this stream using print() method

// This will put the in the

// stream till it is printed on the console

writer.print(1.65);

// Break the line in the stream

// using println() method

writer.println();

writer.flush();

}

catch (Exception e) {

System.out.println(e);

}

}

}

输出:

1.65

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188488.html原文链接:https://javaforall.cn