| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2267 人关注过本帖
标题:在jdk1.6下如何实现格式化输出?
只看楼主 加入收藏
恋恋枫情
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-1
收藏
 问题点数:0 回复次数:12 
在jdk1.6下如何实现格式化输出?

在jdk1.5环境下,可以用System.out.printf()实现格式化输出,貌似jdk1.6不支持哦。。
哪位大仙可以指点下

搜索更多相关主题的帖子: jdk 格式化 输出 环境 printf 
2007-08-01 16:35
heilong
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:777
专家分:0
注 册:2007-6-7
收藏
得分:0 
你用System.out.printf()怎么格试化啊````````````要用System.out.format()这个吧```

风水鸡蛋壳,财去人安乐!----->
2007-08-01 16:57
弑神饕餮
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-6-6
收藏
得分:0 

可以的 两种都可以 都一样 给你写一个很简单的小例子

public class A {
public static void main (String[] args) {
int i=1;
float j=2;
System.out.printf("i is %d\n",i);
System.out.format("j is %f\n",j);
}

}


爱情如潮水般滚滚迩来,总有一天滚滚滚回去!!天长地久惟有java!
2007-08-01 17:45
恋恋枫情
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-1
收藏
得分:0 

System.out.printf()和C中的printf()的用法差不多吧

弱弱的问一下,这个System.out.format()在jdk1。6环境下貌似也不好用哦

2007-08-01 17:52
恋恋枫情
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-1
收藏
得分:0 
以下是引用弑神饕餮在2007-8-1 17:45:09的发言:

可以的 两种都可以 都一样 给你写一个很简单的小例子

public class A {
public static void main (String[] args) {
int i=1;
float j=2;
System.out.printf("i is %d\n",i);
System.out.format("j is %f\n",j);
}

}

执行通不过
出来的是:“Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method format(String, Object[]) in the type PrintStream is not applicable for the arguments (String, float)”

2007-08-01 17:55
heilong
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:777
专家分:0
注 册:2007-6-7
收藏
得分:0 

可以啊`````````我用的就是JDK1.6


风水鸡蛋壳,财去人安乐!----->
2007-08-01 18:15
恋恋枫情
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-1
收藏
得分:0 
以下是引用heilong在2007-8-1 18:15:51的发言:

可以啊`````````我用的就是JDK1.6


我的还是不行
显示:“Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, int)
The method format(String, Object[]) in the type PrintStream is not applicable for the arguments (String, float)

难道与rp有关

2007-08-01 18:31
heilong
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:777
专家分:0
注 册:2007-6-7
收藏
得分:0 
那我就不知道了,不过用这个干吗呢?好像没什么用吗?
直接System.out.println()就可以了啊````````

风水鸡蛋壳,财去人安乐!----->
2007-08-01 18:35
恋恋枫情
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-8-1
收藏
得分:0 
以下是引用heilong在2007-8-1 18:35:19的发言:
那我就不知道了,不过用这个干吗呢?好像没什么用吗?
直接System.out.println()就可以了啊````````

55555。。
数据输出有精度要求的嘛

2007-08-01 19:07
可可熊
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:553
专家分:0
注 册:2007-6-15
收藏
得分:0 
QUOTE:
以下是引用恋恋枫情在2007-8-1 17:55:49的发言:

执行通不过
出来的是:“Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method format(String, Object[]) in the type PrintStream is not applicable for the arguments (String, float)”

程序是不会有问题的 估计是你的JDK的问题吧

2007-08-01 19:15
快速回复:在jdk1.6下如何实现格式化输出?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015447 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved