- 浏览: 229182 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
wcl694216530:
[url][img][img][url][flash=200, ...
oracle的语法start with和connect by nocycle -
gyhbody:
你这个是不是SWC加载错误啊?
flex乱码问题 -
gyhbody:
那 通过什么来查看SWC文件
flex乱码问题 -
liushp1:
[img] [/img]
jsp中redirect和forward的区别 -
little_fei754:
我的输出是120 120。求大神解释。
java表达式类型转换
今天做了一个统计数据的小程序,用到了arrayList 和array,DOM解析,File文件和目录创建:
package config; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class NewTimeDistribution { private List<Integer> costList=new ArrayList<Integer>(); private int max; private int interval=100; private int arrayLength; public int getMax() { return max; } public int getArrayLength() { return arrayLength; } public void setArrayLength(int max) { this.arrayLength =max/interval+1; } public NewTimeDistribution() { super(); } public List<Integer> getCostList() { return costList; } public void parseFile(String fileName) throws ParserConfigurationException, SAXException, IOException{ DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder=dbf.newDocumentBuilder(); Document document=documentBuilder.parse(new File(fileName)); Element element=document.getDocumentElement(); NodeList items=element.getElementsByTagName("item"); for(int i=0;i<items.getLength();i++){ Element item=(Element) items.item(i); NodeList results=item.getElementsByTagName("result"); for(int j=0;j<results.getLength();j++){ Element result=(Element) results.item(j); String tag=result.getAttribute("tag"); if(!(tag.equals("init-player"))){ int cost=Integer.parseInt(result.getAttribute("cost")); costList.add(cost); } } } } public void maxCost(List<Integer> list){ this.max=list.get(0); for(int index=1;index<list.size();index++){ if(max <list.get(index)){ max=list.get(index); } } } public int[] arrayData(List<Integer> list, int length){ int[] arrayCost=new int[length]; for(int index=0;index<list.size();index++){ arrayCost[list.get(index)/interval]++; } return arrayCost; } public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { StringBuilder sb=new StringBuilder(); NewTimeDistribution ntd= new NewTimeDistribution(); ntd.parseFile(args[0]); List<Integer> costList=ntd.getCostList(); ntd.maxCost(costList); int maxCost=ntd.getMax(); ntd.setArrayLength(maxCost); int arrayLength=ntd.getArrayLength(); int[] arrayData=ntd.arrayData(costList, arrayLength); for(int i=0;i<arrayData.length;i++){ System.out.println(100*(i+1)+"\t"+arrayData[i]); sb.append(100*(i+1)+"\t"+arrayData[i]+"\n"); } File file = new File(args[1]); if (!file.exists()) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } file.createNewFile(); } FileOutputStream out = new FileOutputStream(file); out.write(sb.toString().getBytes()); out.flush(); out.close(); } }
发表评论
-
java基础总结1
2013-03-02 21:31 16031、在进行字符串逆转时可以采用StringBuffer对象 ... -
ztf实习开发总结
2012-07-25 20:34 1367weblogic workshop的问题 1、流程管理系统是 ... -
Java中this关键字的几种用法
2012-05-11 18:38 936http://blog.csdn.net/anmei2010/ ... -
java中this的用法
2012-05-09 23:11 0http://blog.csdn.net/anmei2010/ ... -
java核心技术总结八--多线程
2012-05-03 23:32 10661、多线程程序在较低的层次上扩展了多任务的概念: 一个程序同时 ... -
堆和栈的区别
2012-04-11 23:46 722一、预备知识—程序的 ... -
native关键字
2012-04-11 12:53 956java native关键字 一. ... -
什么是重构
2012-04-11 12:50 869重构 ( Refactoring ... -
ConcurrentHashMap 高并发性的实现机制
2012-04-07 23:59 5176简介 ConcurrentHashMap 是 util.co ... -
String和stringbuffer和stringbuilder的区别
2012-03-19 17:13 1017String 字符串常量 StringBuffer 字符串 ... -
java核心技术总结七--异常、日志、断言和调试
2012-03-03 23:09 1675第十一章 1、异常的分类: Th ... -
java核心技术总结六
2012-02-22 21:15 982第10章 1、用命令打jar包: ... -
Java类中构造方法的执行顺序和变量初始化
2012-02-13 11:53 1025看下面的代码先不要运行而尝试给出输出:class A { ... -
java核心技术总结五
2012-01-03 15:46 979第六章 1、接口 (1)、接口中可以包含多个方法,还可以定 ... -
java核心技术总结四
2011-12-30 21:55 2738第五章总结: 1、java用关键字extends代替 ... -
ftp文件的上传与下载
2011-12-30 17:11 1001http://www.cnblogs.com/chen1987 ... -
java核心技术总结三
2011-12-30 09:49 1015第四章:对象和类 1、在类之间,最常见的关系有: ... -
java表达式类型转换
2011-12-16 17:11 1183今天无意中看到我之前做的一个关于java面试题的小测试 ,发现 ... -
Double型数值保留2位小数
2011-12-14 10:32 18015//保留2位小数 public static doubl ... -
java核心技术总结二
2011-12-09 22:44 1080第二章; 1、netBeans是sun公司的集成开 ...
相关推荐
运动会分数统计数据结构课程设计(含源代码)
《银行监管统计数据质量管理良好标准(试行)》实施方案..pdf《银行监管统计数据质量管理良好标准(试行)》实施方案..pdf《银行监管统计数据质量管理良好标准(试行)》实施方案..pdf《银行监管统计数据质量管理良好标准...
循环程序设计实验 试编程统计数据区中正数、零和负数的个数
基于 SPSS 的数据分析(统计数据分析与应用丛书).doc
统计数据会说谎(让你远离数据陷阱)电子书,这是完美epub格式。
网站kpi统计数据
农商银行“金融统计数据质量”活动实施方案.docx农商银行“金融统计数据质量”活动实施方案.docx农商银行“金融统计数据质量”活动实施方案.docx农商银行“金融统计数据质量”活动实施方案.docx农商银行“金融统计...
银监会进一步提升监管统计数据质量的通知.pdf
数学建模-美国历年统计资料和数据汇总-美国各州及大都市区统计数据2006
阐述了统计工作的意义,分析了当前统计工作中存在的问题及信息失真的原因,给出了提高统计数据质量的措施。
世界钢铁统计数据(2002-2021)。包含2002-2021年共20年的数据,对于研究钢铁行业的工作人员会有很大的帮助。 里面包含的内容有: 粗钢产量 钢铁消费 原料 钢铁贸易量 间接贸易量 等
金融网点分县统计数据
03应用统计学统计数据的整理与显示.PPT03应用统计学统计数据的整理与显示.PPT
统计数据采集审核报送制度.pdf
全球粮食和农业统计数据集 数据说明: 粮农统计数据库提供了超过300万份与粮食和农业有关的时间序列和横截面数据。完整的粮农组织数据可以在大的zip文件中找到,而在顶层的CSv文件中有一个(有点过时的)粮农组织统计...
阿里巴巴2010各类行业统计数据.doc
全国县级统计数据.shx
本标准适用范围为根据《银行业监管统计管理暂行办法》(2004年第6号主席令)开展监管统计工作的全部银行业金融机构(下文简称“银行”)。标准的总体框架包含5方面要素,分别为:组织机构及人员,制度建设,系统保障和...
大数据对旅游统计数据质量优化的影响分析.pdf
2021世界钢铁统计数据.pdf