博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
console java_Java Console format()方法与示例
阅读量:2530 次
发布时间:2019-05-11

本文共 2460 字,大约阅读时间需要 8 分钟。

console java

控制台类format()方法 (Console Class format() method)

  • format() method is available in java.io package.

    format()方法在java.io包中可用。

  • format() method is used to write the formatted string to this Console with the help of the given string format and object parameters.

    format()方法用于在给定的字符串格式和对象参数的帮助下将格式化的字符串写入此控制台。

  • format() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    format()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • format() method may throw an exception at the time of formatting this Console.

    在格式化此控制台时, format()方法可能会引发异常。

    IllegalFormatException: This exception may throw when a given string format is not valid.

    IllegalFormatException :如果给定的字符串格式无效,则可能引发此异常。

Syntax:

句法:

public Console format(String frmt, Object... params);

Parameter(s):

参数:

  • String frmt – represents the format string as defined in the Format string.

    字符串frmt –表示格式字符串中定义的格式字符串。

  • Object... params – represents the parameters addressed by the format specifiers in the format string.

    对象...参数 –表示格式字符串中格式说明符所寻址的参数。

Return value:

返回值:

The return type of the method is Console, it returns this Console.

方法的返回类型为Console ,它将返回此Console。

Example:

例:

// Java program to demonstrate the example // of Console format(String frmt , Object… params)// method of Consoleimport java.io.*;public class FormatOfConsole {
public static void main(String[] args) {
try {
// Instantiates Console Console con = System.console(); // Define a string format for rows and columns String frmt = "%1$15s %2$20s %3$20s%n"; // By using format() method isto format the // the given string in rows and column con.format(frmt, "Student_Name", "Student_Add", "Student_ph"); con.format(frmt, "Preeti", "Delhi", "9425667852"); con.format(frmt, "Rahul", "Delhi", "8871459682"); con.format(frmt, "Shreya", "Delhi", "7216589745"); con.format(frmt, "Rama", "Bangalore", "8871568492"); con.format(frmt, "Anjali", "London", "8872589261"); } catch (Exception ex) {
System.out.println(ex.toString()); } }}

Output

输出量

Student_Name          Student_Add           Student_ph         Preeti                Delhi           9425667852          Rahul                Delhi           8871459682         Shreya                Delhi           7216589745           Rama            Bangalore           8871568492         Anjali               London           8872589261

翻译自:

console java

转载地址:http://uhxzd.baihongyu.com/

你可能感兴趣的文章
招行ODC项目表彰
查看>>
js补充知识点-label应用
查看>>
给构造函数(constructor)创建对象(object)
查看>>
局域网访问PHP项目网站 用IP地址进入
查看>>
VM虚拟机,Linux系统安装tools过程遇到 what is the location of the “ifconfig” program
查看>>
Jquery实现循环删除Reaper某一行
查看>>
脚本升级openssh
查看>>
linux学习(3)——vim文本编辑工具
查看>>
快速开发平台如何应用
查看>>
hadoop的理解
查看>>
Java测试当前应用所占用的内存示例
查看>>
网站限制IP访问应该怎么办
查看>>
121. Best Time to Buy and Sell Stock
查看>>
hdu 1005 根据递推公式构造矩阵 ( 矩阵快速幂)
查看>>
安装php扩展
查看>>
mysql统计某一个数据库中有几张表
查看>>
百度移动搜索主要有如下几类结果构成
查看>>
梦断代码最后4章读后感
查看>>
python学习---字符串
查看>>
Python爬虫面试题170道:2019版【1】
查看>>