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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378061.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378061.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378061.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Anaconda自帶Python編譯器Jupyter Notebook顯示代碼行數

ESC:進入命令行模式;按下H即可顯示各種快捷鍵信息 Enter:進入編輯模式 方法一:命令方法 一、點擊代碼段,按ESC,使代碼段顯示藍色,進入命令行模式 二、按下ShiftL,顯示代碼行數 方法…

ajax 服務器響應,ajax-服務器響應

如果需要獲得了來自服務器的響應,則使用XMLHttpRequest 對象的 responseText 或 responseXML 屬性responseText:獲得字符串形式的響應數據,當readyState屬性值變為4時,responseText屬性才可用,表明Ajax請求已經結束例&…

(轉)MOMO的Unity3D研究院之深入理解Unity腳本的執行順序(六十二)

http://www.xuanyusong.com/archives/2378 Unity是不支持多線程的,也就是說我們必須要在主線程中操作它,可是Unity可以同時創建很多腳本,并且可以分別綁定在不同的游戲對象身上,他們各自都在執行自己的生命周期感覺像是多線程&…

SQL/MongoDB 連接并發測試

最近一直在搞mongodb 文件服務器大量文件并發上傳測試,在官方文檔發現mongo是線程安全的,支持單一連接下的并發操作。印象ADO.NET 似乎不支持單一連接并發。于是,測試一下來證實這個疑慮。(前兩篇小記一直糾結mongodb吃內存導致并…

【C、C++基礎】什么時候用 “.” 什么時候用“->”(3個實例搞懂)

從堆棧的角度來說: 從堆棧的角度來說: 對象放在堆上,就要用指針,也就是對象指針->函數; 放在棧上,就對象.函數 那么如何判斷對象放在堆上還是棧上? 從我的另一篇筆記【C grammar】C簡化內存模型可知&am…

java clone方法_Java Calendar clone()方法與示例

java clone方法日歷類clone()方法 (Calendar Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to return the cloned object of this Calendar object. clone()方法用于返回此Calendar對象…

三、Numpy數組操作

一、對圖片各個像素點的像素值進行操作 image.shape[0]:image圖像的height image.shape[1]:image圖像的width image.shape[2]:image圖像的channels import cv2 import numpy as npdef access_pixels(image):print(image.shape)height imag…

picacg服務器維護,picacg的服務器地址是什么

彈性云服務器 ECS彈性云服務器(Elastic Cloud Server)是一種可隨時自助獲取、可彈性伸縮的云服務器,幫助用戶打造可靠、安全、靈活、高效的應用環境,確保服務持久穩定運行,提升運維效率三年低至5折,多種配置可選了解詳情用戶數據注…

Redis-Sampler:深入了解你的Redis存儲

redis-sampler 是Redis作者antirez 同學開發的一個ruby 小工具,用于對Redis存儲概況進行抽樣檢測并給出分析結果。 項目地址:https://github.com/antirez/redis-sampler 使用方式: 下載源碼,執行下面命令: ./redis-sam…

二叉樹筆記(深度遍歷與廣度遍歷+13道leetcode題目(深度3道、廣度10道))

本文章為結合leetcode題目以及公眾號“代碼隨想錄”的文章所做的筆記! 感覺代碼隨想錄的題目整理真的很好,比自己盲目刷題好很多。 目錄1、二叉樹小記1、滿二叉樹與完全二叉樹2、二叉搜索樹3、平衡二叉搜索樹AVL4、二叉樹存儲方式5、二叉樹遍歷方式6、二…

ZZ的計算器

Problem Description ZZ自從上大學以來,腦容量就是以SB計算的,這個吃貨竟然連算術運算也不會了,可是當今的計算機可是非常強大的,作為ACMer, 幾個簡單的算術又算得了什么呢?可是該怎么做呢?ZZ只…

kotlin 覆蓋屬性_Kotlin程序| 方法覆蓋的示例

kotlin 覆蓋屬性方法重載 (Method Overriding) Method overriding allows derived class has the same function name and signature as the base class 方法重寫允許派生類具有與基類相同的函數名稱和簽名 By method overriding we can provide different implementation into…

對視頻中的特征顏色物體(青色水杯)進行跟蹤

方法一:目標物體白色,其余黑色 import cv2 import numpy as npdef extrace_object():capture cv2.VideoCapture("G:/Juptyer_workspace/study/data/yy.mp4")while(True):ret,frame capture.read()if retFalse:breakhsv cv2.cvtColor(frame…

Android實現號碼歸屬地查詢

我們通過發送XML訪問 WebService就可以實現號碼的歸屬地查詢,我們可以使用代理服務器提供的XML的格式進行設置,然后請求提交給服務器,服務器根據請求就會返回給一個XML,XML中就封裝了我們想要獲取的數據。 發送XML 1.通過URL封裝路…

如何從 Datagrid 中獲得單元格的內容與 使用值轉換器進行綁定數據的轉換IValueConverter...

一、如何從 Datagrid 中獲得單元格的內容 DataGrid 屬于一種 ItemsControl, 因此,它有 Items 屬性并且用ItemContainer 封裝它的 items. 但是,WPF中的DataGrid 不同于Windows Forms中的 DataGridView。 在DataGrid的Items集合中,DataGridRow…

【C++ grammar】常量、指針、Usage of using, typedef, and #define

目錄1、常量 (Constant)2、指針(Pointer)3、Usage of using, typedef, and #define1、常量 (Constant) 常量是程序中一塊數據,這個數據一旦聲明后就不能被修改了。 如果這塊數據有一個名字&am…

斯威夫特山地車_斯威夫特| 兩個數字相加的程序

斯威夫特山地車In this program, we will have an idea - how two numbers can be added and displayed as the output on the screen? 在此程序中,我們將有一個想法- 如何將兩個數字相加并顯示為屏幕上的輸出 ? Open XCode terminal and type the fol…

四、色彩空間

一、色彩空間 1、什么是色彩空間? 色彩空間是定義的顏色范圍。 2、常見的色彩空間有哪些? ①RGB ②HSV 在OpenCV中,Hue的值為0~180,之所以不是360是因為,8位存不下,故進行歸一化操作,使得H…

Oracle LOB 詳解

一. 官方說明Oracle 11gR2 文檔:LOB Storagehttp://download.oracle.com/docs/cd/E11882_01/appdev.112/e18294/adlob_tables.htm#ADLOB45267Oracle 10gR2 文檔:LOBs in Tableshttp://download.oracle.com/docs/cd/B19306_01/appdev.102/b14249/adlob_t…

FIFA的完整形式是什么?

國際足聯:國際足球聯合會 (FIFA: Federation Internationale de Football Association) FIFA is an abbreviation of the "Federation Internationale de Football Association" in French. It is also known as the International Federation of Associa…