成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Java怎么將代碼格式化 java中如何格式化時間格式化

設置ctrl+s用于格式化java代碼的方法

window--preference--java--save action--perform the selected action on save 把這個打勾就可以了

成都創(chuàng)新互聯(lián)主要從事網(wǎng)站建設、網(wǎng)站制作、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務琿春,十年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18980820575

JAVA里面如何格式化數(shù)字

樓主你好!給你寫了個測試類希望能幫助你。這兩個個方法只需要傳入你要格式話的數(shù)據(jù),就可以返回你想要的結果了。 package com.line;public class T9 {

/**

* b格式化一般數(shù)據(jù)為財務格式,eg:123,456,789.00/b

*

* @param source

* String

* @return String

*/

public static String getCaiWuData(String source) {

StringBuffer str = new StringBuffer("");

if (source != null !source.equals("") source.length() 0

!source.equals("null")) {

if (source.lastIndexOf(",") 0) {

source =formatStr(source);

}

int dotIndex = 0;

if (source.indexOf(".") 0) {

source += ".00";

}

dotIndex = source.indexOf(".");

int index = 0;

String opt = "";

opt = source.substring(0, 1);

if (opt.equals("-")) {

source = source.substring(1);

str.append("-");

dotIndex = source.indexOf(".");

}

if (dotIndex 3) {

index += 1;

str.append(source.substring(0, dotIndex));

}

if (dotIndex % 3 == 0) {

index += dotIndex / 3;

} else {

index += (dotIndex - dotIndex % 3) / 3;

}

if (index 0 dotIndex = 3) {

for (int i = index; i 0; i--) {

if (i == index) {

str.append(source.substring(0, dotIndex - i * 3));

}

if (dotIndex - i * 3 0) {

str.append(",");

}

if (i = 1) {

str.append(source.substring(dotIndex - i * 3, dotIndex

- (i - 1) * 3));

}

}

}

str.append(source.substring(dotIndex));

}

if (source.length() - source.lastIndexOf(".") 3) {

str.append("0");

}

int dot_index = str.toString().indexOf(".") + 2;

int str_len = str.toString().length();

char[] strArr = str.toString().toCharArray();

StringBuffer rev = new StringBuffer();

for (int i = str_len - 1; i 0; i--) {// 除去尾數(shù)0,小數(shù)點后保留2位

if (i dot_index

Integer.parseInt(new Character(strArr[i]).toString()) 0) {

rev.append(str.toString().substring(0, i + 1));

break;

} else if (i == dot_index (int) strArr[i] = 0) {

rev.append(str.toString().substring(0, dot_index + 1));

break;

}

}

return rev.toString();

}

/**

* b格式化財務數(shù)據(jù)為一般字符串,eg:123456789.00/b

*

* @param source

* String

* @return String

*/

public static String formatStr(String source) {

StringBuffer str = new StringBuffer("");

if (source != null !source.equals("") source.length() 0

!source.equals("null")) {

String temp = source.substring(0, 1);

if (temp.equals("-")) {

source = source.substring(1);

str.append("-");

}

String[] myarr = source.split(",");

int lastIndex = source.lastIndexOf(",");

if (lastIndex 0) {

for (int i = 0; i myarr.length; i++) {

str.append(myarr[i]);

}

}

if (source.lastIndexOf(",") 0) {

str.append(source);

}

if (source.lastIndexOf(".") 0) {

str.append(".00");

}

if (source.length() - source.lastIndexOf(".") 3

!"0".equals(source)) {

str.append("0");

}

} else {

return (str.append("0.00").toString());

}

return str.toString();

}

/**

* @param args

*/

public static void main(String[] args) {

T9 t=new T9();

System.out.println(t.getCaiWuData("1231313"));

System.out.println(t.formatStr("1,231,313.00"));

}}

eclipse怎樣對java代碼自動排版,快速格式化,快速使代碼對齊

使代碼快速對齊的方法有兩種,咱們先看第一種:首先打開代碼

如圖所示,找到"Source",點擊

在彈出的下拉框內,找到"Format",然后點擊

然后對比一下,就可以看到代碼自動對齊了

還有一種方法是直接使用快捷鍵“Ctrl+shift+f”,就ok了

返回代碼區(qū),然后對比一下,就可以看到代碼自動對齊了

JAVA 中獲取時間怎么格式化?

時間格式化輸出主要有兩種方式,代碼如下:

//使用Calendar

Calendar now = Calendar.getInstance();

System.out.println("年:" + now.get(Calendar.YEAR));

System.out.println("月:" + (now.get(Calendar.MONTH) + 1));

System.out.println("日:" + now.get(Calendar.DAY_OF_MONTH));

System.out.println("時:" + now.get(Calendar.HOUR_OF_DAY));

System.out.println("分:" + now.get(Calendar.MINUTE));

ystem.out.println("秒:" + now.get(Calendar.SECOND));

//使用Date

Date d = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

System.out.println("當前時間:" + sdf.format(d));

擴展資料

JAVA中獲取當前系統(tǒng)時間。

import java.util.Date;

import java.text.SimpleDateFormat;

public class NowString {

public static void main(String[] args) {

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//設置日期格式

System.out.println(df.format(new Date()));// new Date()為獲取當前系統(tǒng)時間

}

}

參考資料來源:百度百科:Java

JAVA怎么格式化文檔

先解析文本,然后再格式化輸出

用正則表達式好像也可以,可以試試 答案補充 先找出第一行,以TITANIC開頭的為第一行str1,并將最后一個字母#去掉

然后再讀入其它行,每讀入一行str_i,

然后輸出str+str_i就可以了

程序還是自己寫吧!

怎樣用JAVA格式化一段換行混亂的代碼字符串

代碼如下:

public class Test {

public static void main(String[] args){

String s="12345543211234554321";

StringBuffer s1=new StringBuffer(s);

int index;

for(index=5;indexs1.length();index+=6){

s1.insert(index, '\n');

}

System.out.println(s+"每隔5個字符換行:");

System.out.println(s1);

}

}

名稱欄目:Java怎么將代碼格式化 java中如何格式化時間格式化
標題鏈接:http://jinyejixie.com/article6/docphig.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站維護外貿建站、網(wǎng)站策劃、ChatGPT虛擬主機

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設公司
仲巴县| 简阳市| 永靖县| 慈利县| 广宁县| 新乡县| 抚顺市| 甘谷县| 淮南市| 永登县| 图们市| 阿图什市| 吉木萨尔县| 琼中| 河南省| 康定县| 台湾省| 鄂伦春自治旗| 连城县| 宜良县| 苗栗市| 呼和浩特市| 军事| 宁城县| 专栏| 怀仁县| 平遥县| 稷山县| 岳普湖县| 湾仔区| 普格县| 雷州市| 宜丰县| 新昌县| 金平| 富蕴县| 偃师市| 杭锦后旗| 金门县| 札达县| 临海市|