- 浏览: 1060453 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (399)
- C++ (39)
- Java (74)
- Java界面开发学习笔记 (4)
- Java用户的c++之旅 (0)
- 自言自语 (12)
- DSP (1)
- MCU (0)
- CG (0)
- Jabber (0)
- Gloox (0)
- Linux (11)
- Windows (19)
- Networks (4)
- Jobs (0)
- PHP (1)
- JSP (2)
- 生活 (35)
- C (2)
- Qt4 (2)
- C# (50)
- WPF (5)
- ASP (2)
- FLEX (47)
- SQL (20)
- JavaScript (12)
- SharePoint (6)
- GWT (1)
- Dojo (9)
- HTML (11)
- Others (7)
- 如何安装配置系列 (7)
- UML (2)
- Android (3)
- alibaba (1)
最新评论
-
zxjlwt:
学习了http://surenpi.com
Firefox插件开发: Hello World! -
ylldzz:
楼主知道MVEL怎么调试么
MVEL简介及快速使用 -
blueman2012:
您好,可否提供源码下载,我把您的代码贴过来后,好多报错的,谢谢 ...
Log4J日志解析 -
svygh123:
你的游标都没有关闭呢!
MYSQL游标嵌套循环示例 -
dizh:
写的很好啊
MVEL简介及快速使用
JDK5.0允许象C语言那样直接用printf()方法来格式化输出,并且提供了许多参数来格式化输入,调用也很简单:
System.out.format("Pi is approximately %f", Math.Pi); System.out.printf("Pi is approximately %f", Math.Pi); format( String format, Object... args); printf( String format, Object... args); format( Locale locale, String format, Object... args); printf( Locale locale, String format, Object... args); 同时,以前的formatter类也提供了更完善的方法来格式化,例如: formatter.format("Pi is approximately %1$f," + "and e is about %2$f", Math.PI, Math.E); 格式化元素的构成如下: %[argument_index$][flags][width][.precision]conversion 其中: argument_index是一个正整数,说明了参数的位置,1为取第一个参数 width表示输出的最小字母个数 precision代表数字的小数位数 conversion代表被格式化的参数的类型: 以下是个例子: package format; import java.util.Formatter; public class UsingFormatter { public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: " + "java format/UsingFormatter "); System.exit(0); } String format = args[0]; StringBuilder stringBuilder = new StringBuilder(); Formatter formatter = new Formatter(stringBuilder); formatter.format("Pi is approximately " + format + ", and e is about " + format, Math.PI, Math.E); System.out.println(stringBuilder); } } //控制台调用 java format/UsingFormatter %f //输出 Pi is approximately 3.141593, and e is about 2.718282 //控制台调用 java format/UsingFormatter %.2f //输出 Pi is approximately 3.14, and e is about 2.72 //控制台调用 java format/UsingFormatter %6.2f //输出(有空格来填补长度) Pi is approximately 3.14, and e is about 2.72 //控制台调用 java format/UsingFormatter Pi is approximately 3.14, and e is about 3.14 //改变区域设置 package format; import java.util.Formatter; import java.util.Locale; public class UsingFormatter { public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: " + "java format/UsingFormatter <format string>"); System.exit(0); } String format = args[0]; StringBuilder stringBuilder = new StringBuilder(); Formatter formatter = new Formatter(stringBuilder, Locale.FRANCE); formatter.format("Pi is approximately " + format + ", and e is about " + format, Math.PI, Math.E); System.out.println(stringBuilder); } } //控制台调用 java format/UsingFormatter %.2f //输出 Pi is approximately 3,14, and e is about 2,72 //采用format,printf的可替代写法 package format; public class UsingSystemOut { public static void main(String[] args) { if (args.length != 1) { System.err.println("usage: " + "java format/UsingSystemOut <format string>"); System.exit(0); } String format = args[0]; System.out.format("Pi is approximately " + format + ", and e is approximately " + format, Math.PI, Math.E); } } //控制台调用 java format/UsingSystemOut %.2f%n //输出 Pi is approximately 3.14 , and e is about 2.72 对时间的格式化用字母t来代表,通常在t后面加上特殊的字符来显示时间的某个部分: tr hour and minute, //eg. package format; import java.util.Calendar; public class FormattingDates { public static void main(String[] args) { System.out.printf("Right now it is %tr on " + "%<tA, %<tB %<te, %<tY.%n", Calendar.getInstance()); } } //说明:“<”指示采用的参数为前一个被格式化的参数 //输出 Right now it is 01:55:19 PM on Wednesday, September 22, 2004.
printf()和
format()
方法具有相同的功能. System.out
是 java.io.PrintStream的实例
. PrintStream
, java.io.PrintWriter
, 和 java.lang.String
每个类都有四个新的格式化方法:
f
float,t
timed
decimalo
octalx
hexadecimals
generalc
a Unicode character
%1$.2f
//
输出
tA
the day of the weektB
the name of the monthte
the number of the day of the monthtY
the year
发表评论
-
Interesting interview question…
2011-06-23 19:10 1382Today I was asked this questi ... -
简单易用的Web框架:SummerCool介绍
2011-05-10 19:01 4691SummerCool是国内某大型电子商务平台的架构师自 ... -
[转]Eclipse插件:Java AST View
2011-05-06 16:03 4576转载:http://www.blogjava.net/life ... -
Eclipse之Debug技巧
2011-05-02 15:30 1520你认为你的eclipse debug技能都学会了吗?能够熟 ... -
AccessController.doPrivileged 小记
2011-04-29 20:29 2028原文:http://blog.csdn.net/tea ... -
推荐一个下载源码的网站
2011-04-29 20:26 1202http://olex.openlogic.com/ 这个网 ... -
Java解析xml禁止校验dtd
2011-04-27 21:34 8261今天在做log4j.xml解析的时候,指定了如下的dtd声明: ... -
区分getName、getCanonicalName与getSimpleName
2011-04-27 18:34 5736举例,现有一个类如下: package com.sha ... -
Log4J日志解析
2011-04-25 16:12 6969在有些场景下,需要解析Log4J的日志,以为己用。比如,根据 ... -
分享个不错的网站:看JSON字符串的利器
2011-04-20 20:09 1265分享个不错的网站:看JSON字符串的利器or胸器 http: ... -
Regex:密码验证
2011-04-13 18:45 19484.当且仅当含数字和字母的密码验证 如果密码当且仅当 ... -
JDBC操作数据库时切记关闭资源
2011-04-08 18:14 1810Error: No ManagedConnectio ... -
JDBC:如何将resultset的信息自动封装到pojo里面
2011-04-08 10:32 4264不多说了 直接上代码 Java代码 p ... -
Maven自动升级版本号并打包上传的脚本
2011-04-02 09:52 7436同事写的自动升级版本并打包上传的脚本: echo of ... -
在ibatis中使用$value$引入变量会引入SQLInjection漏洞
2011-04-01 16:26 2275(1)sql语法中的_关键字_.如果sql语句中出现存在用户输 ... -
EqualsBuilder和HashCodeBuilder
2011-03-31 19:30 2173自动化hashCode()和equals() 问题产生:当需 ... -
Eclipse中的Stack Trace Console的使用
2011-03-15 14:47 2977很多的Java程序员(特别是开发Web程序的时候),通常在 ... -
jhat的简单使用
2011-01-18 19:41 2856leak一般会发生在容器类保存对象引用而不删除的时候,替代方法 ... -
关于变更eclipse中maven插件的repository路径
2011-01-10 10:02 16531.打开eclipse 2.window-->ref ... -
Spring 出错:java.lang.NoSuchMethodError: org.springframework.util.ReflectionUtils.
2010-12-13 19:19 2507今天在跑单元测试,使用的是Maven。得到如下Excepti ...
相关推荐
System.out.println("#ERROR# Invalid reader index format '"+args[0]+"'" ); System.exit(3);// throw new Exception( "Invalid reader index '"+args[0]+"'" ); } if ( iReader >= terminals.size() ) {...
System.out.println("***************欢迎使用青鸟超市管理系统***************"); do{ System.out.println("1 .登陆 \n2 .退出系统"); System.out.println("******************请选择数字1/2*************...
public class SJF { public static void main(String[] args) { Scanner in= new Scanner(System.in);... System.out.println("平均周转时间为:"+df.format(AverageWT)); System.out.println
import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAdjusters; public class LocalDateTimeUtil { /** * 比较 localDateTime2 是否在localDateTime1之前(比较大小) * @param ...
Calendar cal = Calendar.getInstance();... System.out.println(parse +"fsgfsf"+format ); cal.setTime(parse); int year1= cal.get(Calendar.YEAR);//获取年份 System.out.println("dssssssssssss"+year1);
System.out.format(“x = %5x”, x); 输出结果为:x = 37 2、System.out.format() int x = 55; System.out.printf(“x = \u201d, x); 输出结果为:x = 7 3、String.format() String提供的静态...
由于JDK8把ODBC驱动删除了... System.out.println("记录时间:" + df.format(rst.getDate("LOGTIME"))); } } catch (Exception e) { e.printStackTrace(); } System.out.println("closed connect"); } }
String d = format.format(time); Date date=format.parse(d); System.out.println("Format To String(Date):"+d); System.out.println("Format To Date:"+date); 运行结果: Format To String(Date):...
System.out.println(date); //将日期和时间按的格式变成我们要求的格式"年-月-日" SimpleDateFormat formater=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sdate=formater.format(date); System.out....
System.out.println(faceId_ErrorCode); FaceIdAnswer output =new FaceIdAnswer(); // answer.answer=""; String Command = "GetRecord(start_time='2018-05-15 12:36:36' end_time=\"" + new SimpleDateFormat...
if (format.equalsIgnoreCase("mp4")) { response.addHeader("Content-Type","video/mp4;cahrset:utf-8"); }else { System.out.println("格式有误!"); } IOUtils.copy(inputStream, response....
this.date=format.format(date); list=new LinkedList(); } public List<Dish> getList() { return list; } public void setList(List<Dish> list) { this.list = list; } public double getSumMoney() { ...
System.out.println("aaa="+ServletActionContext.getActionContext(ServletActionContext.getRequest())); filename=new String[myFile.length]; //获取跟文件夹的绝对路径,"/"代表获取跟路径 String path=...
4:1:1 YCbCr Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 4:2:0 YCbCr Format . . . . . . . . . . . . . . . . . . . . . . ....
System.out.println("Please make sure the input file format are '*.csv'.");System.out.println("Please make sure extra information in input file has been deleted.");System.out.println("And headers ...
Date bir=format.parse(birthday); System.out.println(bir); } catch (ParseException e) { ① // TODO Auto-generated catch block e.printStackTrace(); } } } 代码解析: ① 用SimpleDateFormat解析日期...
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import ...
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); System.out.println("下班倒计时开始..."); timer.schedule(new MyTask(date),0,1000); } //ps:如有不懂请联系作者!解压后是...
System.out.println("First day of week is : " + new SimpleDateFormat("yyyy-MM-dd") .format(getFirstDateByWeek(new Date()))); System.out.println("Last day of week is : " + new ...
What’s Inside Preface 1 Java SE5 and SE6 .................. 2 Java SE6 ............................................The 4th edition...........................Changes ...........................................