java批量格式化代码,java批量格式化代码是什么

java题,如何将数组中的数据格式化输出?(有代码)

import java.util.*;

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的且末网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

class gongzi {

public static void main(String[] args) {

Scanner kb = new Scanner(System. in );

int n = kb.nextInt();

String name = "";

double d = 0;

double e = 0;

double g = 0;

double k = 0;

for (int i = 0; i  n; i++) {

name = kb.next();

d = kb.nextDouble();

e = kb.nextDouble();

g = kb.nextDouble();

k = e + d - g;

}

kb.close();

System.out.printf("%s,Salary is: %.2f + %.2f - %.2f = %.2f%n", name, d, e, g, k);

}

}

java批量格式化文件名

private String convert(String str){

String[] temp = str.split("-");

String resultStr = "";

for(int i=0;itemp.size();i++){

if(temp[i].length() 3){

if(i!=temp.size() - 1){

resultStr = resultStr + "0"+temp[i] + "-";

}else{

resultStr = resultStr + "0"+temp[i];

}

}else{

if(i!=temp.size() - 1){

resultStr = resultStr + temp[i] + "-";

}else{

resultStr = resultStr + temp[i];

}

}

}

return resultStr;

}

参数为你传过来的文件名。自己调试一下,没在eclipse写。有问题问我。

java 中格式化代码(ctrl + shift+f)有什么作用?

就是你没缩进好,写的乱糟糟的,把那部分一选,然后ctrl + shift+f ,他就会自动缩进对齐。

JAVA里面如何格式化数字

楼主你好!给你写了个测试类希望能帮助你。这两个个方法只需要传入你要格式话的数据,就可以返回你想要的结果了。 package com.line;public class T9 {

/**

* b格式化一般数据为财务格式,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--) {// 除去尾数0,小数点后保留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格式化财务数据为一般字符串,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代码自动排版,快速格式化,快速使代码对齐

ctl+shift+f

菜单 - source - Format

鼠标右键 - source - Format

怎么格式化JSP里的java代码

你好,如下设置可以实现:

打开eclipse选择Window -Preferences

再选择 Web = HTML Files = Editor

在 Inline Elements列表里添加所有的标签进去

然后按 CTRL+SHIFT+F就可以格式化了。

新闻标题:java批量格式化代码,java批量格式化代码是什么
网页地址:https://www.cdcxhl.com/article8/hsipop.html

成都网站建设公司_创新互联,为您提供网站设计公司标签优化定制网站域名注册网站维护品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设