楼主你好!给你写了个测试类希望能帮助你。这两个个方法只需要传入你要格式话的数据,就可以返回你想要的结果了。 package com.line;public class T9 {
创新互联建站是专业的綦江网站建设公司,綦江接单;提供成都做网站、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行綦江网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
/**
* 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"));
}}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class FormateBankAccountId {
ListString standardBankAccountIdFormat ;
public FormateBankAccountId(String propertiesFileName) throws FileNotFoundException, IOException
{
// 加载资源文件
Properties properties = new Properties();
properties.load(new FileReader(propertiesFileName));
this.standardBankAccountIdFormat = new ArrayListString();
int keyNumber = 1;
String value = null;
// 读取键值对,键的格式是: formate_1 ,..., formate_10,...,formate_100 等
while( ( value = properties.getProperty("formate_" + keyNumber++) ) != null)
{
value = value.trim();
this.standardBankAccountIdFormat.add(value);
}
}
public ListString formate(String orginalBankAccountId)
{
ListString proceededlBankAccountIds = new :
你好,如下设置可以实现:
打开eclipse选择Window -Preferences
再选择 Web = HTML Files = Editor
在 Inline Elements列表里添加所有的标签进去
然后按 CTRL+SHIFT+F就可以格式化了。
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);
}
}
先解析文本,然后再格式化输出
用正则表达式好像也可以,可以试试 答案补充 先找出第一行,以TITANIC开头的为第一行str1,并将最后一个字母#去掉
然后再读入其它行,每读入一行str_i,
然后输出str+str_i就可以了
程序还是自己写吧!