console java_Java Console format()方法与示例
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 Console
import 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
翻译自: https://www.includehelp.com/java/console-format-method-with-example.aspx
console java
console java_Java Console format()方法与示例相关推荐
- java formatter 填充_Java Formatter format()方法及示例
格式化程序类format()方法 语法:public Formatter format(Locale lo, String frmt, Object... args); public Formatte ...
- drawimage的用法 java_Java Graphics.drawImage方法代码示例
本文整理汇总了Java中javax.microedition.lcdui.Graphics.drawImage方法的典型用法代码示例.如果您正苦于以下问题:Java Graphics.drawImag ...
- console java_Java Console writer()方法与示例
console java 控制台类writer()方法 (Console Class writer() method) writer() method is available in java.io ...
- object getkey java_Java S3Object.getKey方法代码示例
import com.amazonaws.services.s3.model.S3Object; //导入方法依赖的package包/类 private S3Object decipher(GetOb ...
- x509代码实例java_Java X509AttributeCertificate.getIssuer方法代码示例
import org.bouncycastle.x509.X509AttributeCertificate; //导入方法依赖的package包/类 /** * Parses the contents ...
- setresult()java_Java ResultSet getType()方法与示例
该java.sql.ResultSet中的接口表示由SQL语句返回这样的表格数据. 即ResultSet对象保存由执行查询数据库的语句的方法返回的表格数据(通常是Statement接口的execute ...
- setlength java_Java StringBuilder setLength()方法与示例
StringBuilder类setLength()方法setLength()方法在java.lang包中可用. setLength()方法用于在将字符序列替换为新字符序列时设置字符序列的长度,因此该序 ...
- enclosing type java_Java ResolvedJavaType.getEnclosingType方法代码示例
import jdk.vm.ci.meta.ResolvedJavaType; //导入方法依赖的package包/类 @Override protected boolean verify(Struc ...
- containskey java_Java Hashtable containsKey()方法与示例
哈希表类containsKey()方法containsKey()方法在java.util包中可用. containsKey()方法用于检查给定对象是否为键元素(key_ele). containsKe ...
最新文章
- applicationcontext添加配置_Spring源码分析2 — spring XML配置文件的解析流程
- Distance metric learning
- mysql8 允许外网访问
- csdn自定义模块backup
- 移动端效果之Picker
- Python模块学习——tempfile
- c/c++ 实参、形参、值传递、地址传递的区别与关系 ---- 授人以鱼不如授人以渔
- Android Mms 数据库
- 系统动力学模型_RCR新文:基于系统动力学模型的中国煤炭产能情景预测
- RHCS集群 切换时defunct僵尸进程解决方案
- yuicompressor java_YUI Compressor
- 尚学堂 马士兵 struts_2视频教程 笔记心得 1——30课详解
- 猫哥教你写爬虫 034--爬虫-BeautifulSoup实践
- 绿色版软件 tomcat+eclipse的使用
- 做网赚想要赚到钱,心态很重要
- android黑科技系列——微信抢红包插件原理解析和开发实现
- 为啥一定要用残差图检查你的回归分析?
- 使用了未经检查或不安全的操作_基建安全质量“四不两直”检查现场检查表
- 心靜如水的時候聽音樂
- git push origin HEAD:refs/for/master解析
热门文章
- 教你读懂Ajax的工作原理
- Bash脚本教程之启动环境
- java-JSON: Expected value at 1:0 错误
- cmake 构建路径_新手必备:win10 系统下 VSCode+CMake+Clang+GCC 环境的搭建
- 计算机四级必背知识点,2019年6月计算机四级数据库工程师必备考点
- ccf命令行选项只能用c实现_CCF-201403-3-命令行选项
- jq 方法函数(淡入淡出,查找元素,过滤)遍历
- 酷毙了!三种风格的全屏幻灯片效果【附源码下载】
- CSS制作简单loading动画
- Redis与Zookeeper实现分布式锁的区别