??xml version="1.0" encoding="utf-8" standalone="yes"?>精品电影一区,亚洲国产欧美一区二区三区丁香婷,久久久久国产精品一区二区http://www.aygfsteel.com/jnbzwm/category/46213.html敏捷是一条很长的路,摸烦着前进着zh-cnSun, 10 Apr 2011 08:23:45 GMTSun, 10 Apr 2011 08:23:45 GMT60详细描述 快速排?的过E?附Java实现http://www.aygfsteel.com/jnbzwm/archive/2011/04/09/347958.html??/dc:creator>??/author>Sat, 09 Apr 2011 09:37:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2011/04/09/347958.htmlhttp://www.aygfsteel.com/jnbzwm/comments/347958.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2011/04/09/347958.html#Feedback1http://www.aygfsteel.com/jnbzwm/comments/commentRss/347958.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/347958.html本文为原创,Ƣ迎转蝲Q{载请注明出处BlogJava?/span>
快速排序的法思想Q?br /> 快速排序采用了分治的策略,原问题分解q个规模更小但结构与原问题相似的子问题。用递归Ҏ解决子问题,然后这些子问题的解l合为原问题的解?br />
快速排序的E序的一般过E可单描qCؓQ?br /> 1.用统一的方法取?pivot(??br /> 2.Ҏpivot 对已有数l进行排?br />     1) array[pivot]存储在tmp变量中,作ؓ比较基准?br />     以low、high分别从前向后、从后向前遍历数l?br />     2) 从后向前遍历Q找到第一个小于tmp的数Q将其移动到low的位|?br />     3) 从前向后遍历Q找到第一个大于tmp的数Q将其移动到high的位|?br />     4) 循环2?步,直到两指针重?即退出@环的条g?low >= high)Q将tmpUd到low(此时low与high重合)的位|,q将lowq回成ؓ新的pivot?br />     5) Ҏ4步返回的pivotQ对已有数组q行划分Q?~pivot-1 ?pivot+1 ?array.lenghtQ递归1?步。直到调用退出?br />
怿对于以上理论大家一定是耳熟能详了,但理解v来还是比较抽象,下面我就用Exceld单的描述一?快速排?的过E?br />
假设我们要写一个程序对已有数组q行排序Q简单v见,讑֮待排序数lؓ int[] array = { 4, 2, 1, 7, 5, 3, 8, 6 }。对其用快速排序算法进行排序,q程描述如下Q?br /> 1.Ҏ已有待排序数l,取得pivotQ我在这里取得pivot的策略就??数组的第一个数Q这里即?4?br />    tmp = 4Q?br />
待排序数l:黄色底色表示pivot?br />


2.从后向前UdhighQ找到第一个小于tmp的数Q则该数移动到low的位|?br />


3.从前向后UdlowQ找到第一个大于tmpQ?Q的敎ͼ其Ud到high的位|?br />

4.然后再向前移动highQ试图找到第一个小于tmp(4)的数Q但没有扑ֈQ此时low与high重叠Q将tmp的值放入low的位|,q将low作ؓpivotq回?br />



  Ҏ新的pivotq行递归调用Q将原待排序数组 分解Z块,index区间分别??Q??Q即以下两个子数l?br />   (q未新徏数组Q只是只xq个区间的数据,对其q行排序Q也是问题分解ؓ两个的子问题,但问题很cM?
 

q两个数l的排序q程q里׃MQ一Lq程?br />
下面来看看实现的代码Q与刚刚的过E描q是W合的:

package com.bz.sort.algorithm;

public class QuickSort {
    
/**
     * 对外调用的方法入口?br />      * 
@param array 待排序数l?br />      */

    
public void sort(int[] array) {
        
if (array == null || array.length < 0{
            
throw new RuntimeException("待排序数l中无数据?/span>");
        }


        
// 排序
        sort(array, 0, array.length - 1);
    }


    
/**
     * 快速排序?br />      * 
@param arr 待排序数l?br />      * @param left x的区?br />      * @param right x的区?br />      */

    
private void sort(int[] arr, int left, int right) {
        
if (left >= right) {
            
return;
        }

        
// 取得pivot位置Q这里的{略是取得最的indexQ即q回left
        int pivot = findPivot(arr, left, right);
        
// 排序q新计出pivot
        pivot = partion(arr, left, right, pivot);

        
// 以pivotZ心将原数l分解成两块Q递归排序
        sort(arr, left, pivot - 1);
        sort(arr, pivot 
+ 1, right);
    }


    
/**
     * 排序q返回新的pivot
     * 
@param arr 待排序数l?br />      * @param left 区间
     * 
@param right 区间
     * 
@param pivot ?br />      * @return 
     
*/

    
private int partion(int[] arr, int left, int right, int pivot) {
        
int tmp = arr[pivot];
        
int low = left;
        
int high = right;
        
while (low < high) {
            
// 从后向前遍历数组Q找到第一个小于arr[pivot]的数
            while (low < high && tmp < arr[high]) {
                high
--;
            }

            arr[low] 
= arr[high];

            
// 从前向后遍历数组Q找到第一个大于arr[pivot]的数
            while (low < high && tmp >= arr[low]) {
                low
++;
            }

            arr[high] 
= arr[low];
        }


        
// 此时low与high重合Q将tmp的值移动到low的位|?/span>
        arr[low] = tmp;
        
// low当作新的pivotq回
        return low;
    }


    
/**
     * 取得排序的u
     * 
@param array
     * 
@return
     
*/

    
protected int findPivot(int[] array, int left, int right) {
        
if (array == null || array.length < 0{
            
throw new RuntimeException("待排序数l中无数据?/span>");
        }

        
// 选择W一个元素ؓ?/span>
        return left;
    }

}

 


试代码如下Q?br />

package com.bz.sort.algorithm;

import org.junit.Test;

import junit.framework.Assert;

public class QuickSortTest {
    @Test
    
public void testSort() {
        
int[] array = 42175386 };
        QuickSort qs 
= new QuickSort();
        qs.sort(array);
        
for (int i = 0; i < array.length - 1; i++{
            Assert.assertTrue(array[i] 
<= array[i + 1]);
        }

    }

}


注:此代码只?演示 排序q程?

]]>
java代码实现利用 classloader 动态加?jar包、文件夹到classpath?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2011/04/01/347491.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Fri, 01 Apr 2011 12:39:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2011/04/01/347491.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/347491.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2011/04/01/347491.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/347491.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/347491.html</trackback:ping><description><![CDATA[     摘要: 在项目中实现了一个工?独立q行的Java工程Q打成jar包后 通过 java -jar **.jar 执行的?Q该工具通过配置能够实现一些业务功能, q且该工h供了接口与抽象类Q供其他人扩展它的功能? q就涉及C个问题:别h在扩展它的时候,需要引入一些jar或者配|文Ӟ本来工具依赖的jar和配|文仉记录在manifest文g中了Q?不可能别人加了jar包和配置文gp修改ma...  <a href='http://www.aygfsteel.com/jnbzwm/archive/2011/04/01/347491.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jnbzwm/aggbug/347491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2011-04-01 20:39 <a href="http://www.aygfsteel.com/jnbzwm/archive/2011/04/01/347491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过Spring实现对自定义注解属性进行资源注?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333721.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Mon, 04 Oct 2010 02:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333721.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/333721.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333721.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/333721.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/333721.html</trackback:ping><description><![CDATA[通过上一?<a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html">利用自定义Java注解实现资源注入</a> 介绍的方法,我们实现了通过自定义注解完成了对DataSource资源的注入,但在实际应用中,我们通常不希望去昑ּ的去声明q样的MyAnnotationBeanProcessor对象来帮助我们完成注入,而是希望通过Spring帮我?#8220;悄悄?#8221;完成?br /> l?<a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html">利用自定义Java注解实现资源注入</a> 里的代码(部分代码)不变Q我们希望在试cM以如下方法调用便可以实现资源的注入:<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> com.annotation.MyService;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_140_541_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_541_Open_Text.style.display='none'; Codehighlighter1_140_541_Closed_Image.style.display='inline'; Codehighlighter1_140_541_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_140_541_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_140_541_Closed_Text.style.display='none'; Codehighlighter1_140_541_Open_Image.style.display='inline'; Codehighlighter1_140_541_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SpringWiringTest </span><span id="Codehighlighter1_140_541_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_140_541_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_185_539_Open_Image" onclick="this.style.display='none'; Codehighlighter1_185_539_Open_Text.style.display='none'; Codehighlighter1_185_539_Closed_Image.style.display='inline'; Codehighlighter1_185_539_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_185_539_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_185_539_Closed_Text.style.display='none'; Codehighlighter1_185_539_Open_Image.style.display='inline'; Codehighlighter1_185_539_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String args[]) </span><span id="Codehighlighter1_185_539_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_185_539_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        ClassPathXmlApplicationContext ctx </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ClassPathXmlApplicationContext(</span><span style="color: #000000">"</span><span style="color: #000000">com/spring/applicationContext.xml</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        MyService b </span><span style="color: #000000">=</span><span style="color: #000000"> (MyService)ctx.getBean(</span><span style="color: #000000">"</span><span style="color: #000000">myService</span><span style="color: #000000">"</span><span style="color: #000000">); </span><span style="color: #008000">//</span><span style="color: #008000"> 通过Springȝ理beanQ此时已完成了对标有DataSource注解的资源的注入</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        System.out.println(b.selectForObjectFromB(</span><span style="color: #000000">""</span><span style="color: #000000">, </span><span style="color: #0000ff">null</span><span style="color: #000000">));<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(b.selectForObjectFromA(</span><span style="color: #000000">""</span><span style="color: #000000">, </span><span style="color: #0000ff">null</span><span style="color: #000000">));<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 注:MyServicecd现在 <a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html">利用自定义Java注解实现资源注入</a> 中?br /> <br /> Z实现上面的目标,我们׃能用MyAnnotationBeanProcessor.javacL实现对资源的注入了,我们必须实现一个能融入Spring的BeanProcessorcL行?br /> DataSourceBeanProcessor.javacd现BeanPostProcessor、PriorityOrdered接口Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">import</span><span style="color: #000000"> java.lang.reflect.Field;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.beans.BeansException;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.beans.factory.config.BeanPostProcessor;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.core.Ordered;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.core.PriorityOrdered;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_323_980_Open_Image" onclick="this.style.display='none'; Codehighlighter1_323_980_Open_Text.style.display='none'; Codehighlighter1_323_980_Closed_Image.style.display='inline'; Codehighlighter1_323_980_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_323_980_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_323_980_Closed_Text.style.display='none'; Codehighlighter1_323_980_Open_Image.style.display='inline'; Codehighlighter1_323_980_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> DataSourceBeanProcessor </span><span style="color: #0000ff">implements</span><span style="color: #000000"> BeanPostProcessor, PriorityOrdered </span><span id="Codehighlighter1_323_980_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_323_980_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    @Override<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #008000">//</span><span style="color: #008000"> 在这里完成资源注?/span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Object postProcessAfterInitialization(Object bean, String beanName)<br /> <img id="Codehighlighter1_465_733_Open_Image" onclick="this.style.display='none'; Codehighlighter1_465_733_Open_Text.style.display='none'; Codehighlighter1_465_733_Closed_Image.style.display='inline'; Codehighlighter1_465_733_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_465_733_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_465_733_Closed_Text.style.display='none'; Codehighlighter1_465_733_Open_Image.style.display='inline'; Codehighlighter1_465_733_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">throws</span><span style="color: #000000"> BeansException </span><span id="Codehighlighter1_465_733_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_465_733_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        Class</span><span style="color: #000000"><?></span><span style="color: #000000"> cls </span><span style="color: #000000">=</span><span style="color: #000000"> bean.getClass();<br /> <img id="Codehighlighter1_559_706_Open_Image" onclick="this.style.display='none'; Codehighlighter1_559_706_Open_Text.style.display='none'; Codehighlighter1_559_706_Closed_Image.style.display='inline'; Codehighlighter1_559_706_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_559_706_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_559_706_Closed_Text.style.display='none'; Codehighlighter1_559_706_Open_Image.style.display='inline'; Codehighlighter1_559_706_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">for</span><span style="color: #000000"> (Field field : cls.getDeclaredFields()) </span><span id="Codehighlighter1_559_706_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_559_706_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_622_696_Open_Image" onclick="this.style.display='none'; Codehighlighter1_622_696_Open_Text.style.display='none'; Codehighlighter1_622_696_Closed_Image.style.display='inline'; Codehighlighter1_622_696_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_622_696_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_622_696_Closed_Text.style.display='none'; Codehighlighter1_622_696_Open_Image.style.display='inline'; Codehighlighter1_622_696_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (field.isAnnotationPresent(DataSource.</span><span style="color: #0000ff">class</span><span style="color: #000000">)) </span><span id="Codehighlighter1_622_696_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_622_696_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />                DataSourceStaticWiring.wiring(bean, field);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> bean;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    @Override<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> Object postProcessBeforeInitialization(Object bean, String beanName)<br /> <img id="Codehighlighter1_860_887_Open_Image" onclick="this.style.display='none'; Codehighlighter1_860_887_Open_Text.style.display='none'; Codehighlighter1_860_887_Closed_Image.style.display='inline'; Codehighlighter1_860_887_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_860_887_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_860_887_Closed_Text.style.display='none'; Codehighlighter1_860_887_Open_Image.style.display='inline'; Codehighlighter1_860_887_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">throws</span><span style="color: #000000"> BeansException </span><span id="Codehighlighter1_860_887_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_860_887_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> bean;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />    @Override<br /> <img id="Codehighlighter1_930_978_Open_Image" onclick="this.style.display='none'; Codehighlighter1_930_978_Open_Text.style.display='none'; Codehighlighter1_930_978_Closed_Image.style.display='inline'; Codehighlighter1_930_978_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_930_978_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_930_978_Closed_Text.style.display='none'; Codehighlighter1_930_978_Open_Image.style.display='inline'; Codehighlighter1_930_978_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> getOrder() </span><span id="Codehighlighter1_930_978_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_930_978_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> Ordered.LOWEST_PRECEDENCE;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 下面来看DataSourceStaticWiring的实玎ͼ与前一?里的DataSourceWiring.javacȝ比,改动Ҏ以下三个Q?br /> 1.不需要实现IFieldWiring接口<br /> 2.删除annotationClassҎ<br /> 3.wiringҎ修改为staticҎ<br /> 具体代码如下Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">import</span><span style="color: #000000"> java.lang.reflect.Field;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_69_642_Open_Image" onclick="this.style.display='none'; Codehighlighter1_69_642_Open_Text.style.display='none'; Codehighlighter1_69_642_Closed_Image.style.display='inline'; Codehighlighter1_69_642_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_69_642_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_69_642_Closed_Text.style.display='none'; Codehighlighter1_69_642_Open_Image.style.display='inline'; Codehighlighter1_69_642_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> DataSourceStaticWiring </span><span id="Codehighlighter1_69_642_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_69_642_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /> <img id="Codehighlighter1_130_640_Open_Image" onclick="this.style.display='none'; Codehighlighter1_130_640_Open_Text.style.display='none'; Codehighlighter1_130_640_Closed_Image.style.display='inline'; Codehighlighter1_130_640_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_130_640_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_130_640_Closed_Text.style.display='none'; Codehighlighter1_130_640_Open_Image.style.display='inline'; Codehighlighter1_130_640_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> wiring(Object object, Field field) </span><span id="Codehighlighter1_130_640_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_130_640_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        Object fieldObj </span><span style="color: #000000">=</span><span style="color: #000000"> ReflectUtils.getFieldValue(object, field.getName());<br /> <img id="Codehighlighter1_241_271_Open_Image" onclick="this.style.display='none'; Codehighlighter1_241_271_Open_Text.style.display='none'; Codehighlighter1_241_271_Closed_Image.style.display='inline'; Codehighlighter1_241_271_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_241_271_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_241_271_Closed_Text.style.display='none'; Codehighlighter1_241_271_Open_Image.style.display='inline'; Codehighlighter1_241_271_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (fieldObj </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000">) </span><span id="Codehighlighter1_241_271_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_241_271_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        DataSource annotation </span><span style="color: #000000">=</span><span style="color: #000000"> field.getAnnotation(DataSource.</span><span style="color: #0000ff">class</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        String type </span><span style="color: #000000">=</span><span style="color: #000000"> annotation.type();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        String sqlMap </span><span style="color: #000000">=</span><span style="color: #000000"> annotation.sqlMap();<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span><span style="color: #008000">//</span><span style="color: #008000"> q里可以用缓存来实现Q不用每ơ都d建新的SqlMapClient对象</span><span style="color: #008000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: #000000">        SqlMapClient sqlMapImpl </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SqlMapClient(sqlMap, type);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        ReflectUtils.setFieldValue(object, field.getName(), SqlMapClient.</span><span style="color: #0000ff">class</span><span style="color: #000000">, sqlMapImpl);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 注:SqlMapClient、ReflectUtils实现在上一?<a id="viewpost1_TitleUrl" href="http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html">利用自定义Java注解实现资源注入</a> 中?br /> <br /> 代码已准备就l,接下来是配置SpringQapplicationContext.xml<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff"><?</span><span style="color: #ff00ff">xml version="1.0" encoding="UTF-8"</span><span style="color: #0000ff">?></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff"><</span><span style="color: #800000">beans </span><span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://www.springframework.org/schema/beans"</span><span style="color: #ff0000"> xmlns:xsi</span><span style="color: #0000ff">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: #ff0000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    xmlns:aop</span><span style="color: #0000ff">="http://www.springframework.org/schema/aop"</span><span style="color: #ff0000"> xmlns:tx</span><span style="color: #0000ff">="http://www.springframework.org/schema/tx"</span><span style="color: #ff0000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    xmlns:context</span><span style="color: #0000ff">="http://www.springframework.org/schema/context"</span><span style="color: #ff0000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    xsi:schemaLocation</span><span style="color: #0000ff">="http://www.springframework.org/schema/beans <br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/aop <br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/tx <br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />                        http://www.springframework.org/schema/context<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />           http://www.springframework.org/schema/context/spring-context-2.5.xsd"</span><span style="color: #ff0000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    default-lazy-init</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    <br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #008000"><!--</span><span style="color: #008000"> 自定义的BeanProcessor </span><span style="color: #008000">--></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #0000ff"><</span><span style="color: #800000">bean </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="com.annotation.DataSourceBeanProcessor"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #0000ff"><</span><span style="color: #800000">context:component-scan </span><span style="color: #ff0000">base-package</span><span style="color: #0000ff">="com.annotation"</span><span style="color: #ff0000"> </span><span style="color: #0000ff">/></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #008000"><!--</span><span style="color: #008000"> 试用bean </span><span style="color: #008000">--></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #0000ff"><</span><span style="color: #800000">bean </span><span style="color: #ff0000">id</span><span style="color: #0000ff">="myService"</span><span style="color: #ff0000"> class</span><span style="color: #0000ff">="com.annotation.MyService"</span><span style="color: #ff0000"> destroy-method</span><span style="color: #0000ff">="close"</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="color: #0000ff"></</span><span style="color: #800000">bean</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff"></</span><span style="color: #800000">beans</span><span style="color: #0000ff">></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span></div> <br /> 试代码其实已经在前面列出来了。SpringWiringTest.java<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #0000ff">import</span><span style="color: #000000"> org.springframework.context.support.ClassPathXmlApplicationContext;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> com.annotation.MyService;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><br /> <img id="Codehighlighter1_140_494_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_494_Open_Text.style.display='none'; Codehighlighter1_140_494_Closed_Image.style.display='inline'; Codehighlighter1_140_494_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_140_494_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_140_494_Closed_Text.style.display='none'; Codehighlighter1_140_494_Open_Image.style.display='inline'; Codehighlighter1_140_494_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> SpringWiringTest </span><span id="Codehighlighter1_140_494_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_140_494_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_185_492_Open_Image" onclick="this.style.display='none'; Codehighlighter1_185_492_Open_Text.style.display='none'; Codehighlighter1_185_492_Closed_Image.style.display='inline'; Codehighlighter1_185_492_Closed_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_185_492_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_185_492_Closed_Text.style.display='none'; Codehighlighter1_185_492_Open_Image.style.display='inline'; Codehighlighter1_185_492_Open_Text.style.display='inline';" alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String args[]) </span><span id="Codehighlighter1_185_492_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img alt="" src="http://www.aygfsteel.com/Images/dot.gif" /></span><span id="Codehighlighter1_185_492_Open_Text"><span style="color: #000000">{<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        ClassPathXmlApplicationContext ctx </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> ClassPathXmlApplicationContext(</span><span style="color: #000000">"</span><span style="color: #000000">com/spring/applicationContext.xml</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        MyService b </span><span style="color: #000000">=</span><span style="color: #000000"> (MyService)ctx.getBean(</span><span style="color: #000000">"</span><span style="color: #000000">myService</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(b.selectForObjectFromB(</span><span style="color: #000000">""</span><span style="color: #000000">, </span><span style="color: #0000ff">null</span><span style="color: #000000">));<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" />        System.out.println(b.selectForObjectFromA(</span><span style="color: #000000">""</span><span style="color: #000000">, </span><span style="color: #0000ff">null</span><span style="color: #000000">));<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span></span><span style="color: #000000"><br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span></span></div> <br /> 执行l果Q?br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">SqlMapClient[sqlMap</span><span style="color: #000000">=</span><span style="color: #000000">com</span><span style="color: #000000">/</span><span style="color: #000000">annotation</span><span style="color: #000000">/</span><span style="color: #000000">sql</span><span style="color: #000000">-</span><span style="color: #000000">map</span><span style="color: #000000">-</span><span style="color: #000000">config</span><span style="color: #000000">-</span><span style="color: #000000">B.xml,type</span><span style="color: #000000">=</span><span style="color: #000000">B]<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />SqlMapClient[sqlMap</span><span style="color: #000000">=</span><span style="color: #000000">com</span><span style="color: #000000">/</span><span style="color: #000000">annotation</span><span style="color: #000000">/</span><span style="color: #000000">sql</span><span style="color: #000000">-</span><span style="color: #000000">map</span><span style="color: #000000">-</span><span style="color: #000000">config</span><span style="color: #000000">-</span><span style="color: #000000">A.xml,type</span><span style="color: #000000">=</span><span style="color: #000000">A]</span></div> <br /> q果可见,我们利用Spring完成了对DataSource资源的注入了?br /> <br /> 在这里如果还x展的话,需要新建类假设为InParamBeanProcessorQ实现BeanPostProcessor、PriorityOrdered接口Q然后实现其中的ҎQ对资源q行注入Q这里就是扩展Spring了,与本介l的Ҏ相同?br /> <br /> <span style="color: red">注:以上代码重在演示Q其实这个需求可以在Spring中管理两个不同的SqlMapClient对象Q然后通过Spring的自动注入实现?br /> </span><br /> 本文为原创,Ƣ迎转蝲Q{载请注明出处<a title="BlogJava" href="http://www.aygfsteel.com/jnbzwm/">BlogJava</a>?br /> <img src ="http://www.aygfsteel.com/jnbzwm/aggbug/333721.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2010-10-04 10:31 <a href="http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333721.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用自定义Java注解实现资源注入http://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html??/dc:creator>??/author>Mon, 04 Oct 2010 02:19:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.htmlhttp://www.aygfsteel.com/jnbzwm/comments/333720.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/10/04/333720.html#Feedback0http://www.aygfsteel.com/jnbzwm/comments/commentRss/333720.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/333720.html阅读全文

]]>
Java SSHq程执行Shell脚本实现http://www.aygfsteel.com/jnbzwm/archive/2010/09/26/332944.html??/dc:creator>??/author>Sun, 26 Sep 2010 05:03:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/26/332944.htmlhttp://www.aygfsteel.com/jnbzwm/comments/332944.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/26/332944.html#Feedback3http://www.aygfsteel.com/jnbzwm/comments/commentRss/332944.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/332944.html阅读全文

]]>
Runtime.getRuntime().exec(cmd)使用不当引v的java.io.IOException: Too many open fileshttp://www.aygfsteel.com/jnbzwm/archive/2010/09/14/332009.html??/dc:creator>??/author>Tue, 14 Sep 2010 11:36:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/14/332009.htmlhttp://www.aygfsteel.com/jnbzwm/comments/332009.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/14/332009.html#Feedback2http://www.aygfsteel.com/jnbzwm/comments/commentRss/332009.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/332009.html今天生环境的一个Java应用E序的日志里Q出C很不和谐的记录:
java.io.IOException: Too many open files

在网上查了一些关于此异常的解x案,基本上都是说要扩大linuxpȝ的文件句柄数限制?br /> 但如果程序对于Socket、Stream{用后没能及时关闭的话Q扩大这个文件句柄数限制是治标不L的?br />
我先是在试环境扩大了linux的文件句柄数限制Q随后提高测试压力,q一D|间后发现q是会报q个异常?br /> Q中间也用lsof命o查看占用的文件句柄数Q不断的增加啊,心寒啊。)
现象??lsof -p *** 来查看,形如
java    22055 webapp   21w  FIFO                0,6          29300342 pipe
java    22055 webapp   22r  FIFO                0,6          29256305 pipe

在不断增加?br />
所以我果断对代码进行了排查。文件的IO操作、对数据库的操作Q看了都没有什么问题,
最后排查到由JavaE序去调用Shell脚本的代码,

代码写的q是很简单的Q看上去很清晎ͼ但是有明昄问题Q?/p>

Process proc = Runtime.getRuntime().exec(cmd);
//?img alt="" src="http://www.aygfsteel.com/Images/dot.gif" />对proc.getErrorStream()、proc.getInputStream()的操作?/span>
proc.waitFor();
return proc.exitValue();


q里的问题是 Ҏ没有在finally处做关闭处理。这个问题比较明显?br /> q有一个问题就是Process的用问题,

如果对Process的不熟悉的话Q可能会以ؓreturn proc.exitValue();之后׃事大吉了?br /> QexitValue()实很像是已l退Zq得到返回值的意思,估计是这个方法的名字qh了我们的开发h员。)
实际不然Q看Jdk的帮助文档可以发玎ͼ要通过destroy()来实现对子进E的销毁ƈ释放占用的File Descriptor?/p>

q个问题Q短旉的测试是不会有问题的Q但在投入生产后Q随着E序的长期运行,开发中的疏忽就会暴露了?br /> 所以在对用的Ҏ拿不准的情况下,q是要多做调查,谨慎使用啊?br />
希望能让在排查类似问题的朋友注意Q如果你排查的代码中也存在Runtime.getRuntime().exec(cmd)q样的调用,那么L保那D代码没有问题?br />
本文为原创,Ƣ迎转蝲Q{载请注明出处BlogJava?/span>



]]>
手?Spring中的PropertyPlaceholderConfigurer.javahttp://www.aygfsteel.com/jnbzwm/archive/2010/09/13/331898.html??/dc:creator>??/author>Mon, 13 Sep 2010 07:44:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/13/331898.htmlhttp://www.aygfsteel.com/jnbzwm/comments/331898.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/13/331898.html#Feedback2http://www.aygfsteel.com/jnbzwm/comments/commentRss/331898.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/331898.html阅读全文

]]>
StringcsubstringҎD的Java内存泄漏问题http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330559.html??/dc:creator>??/author>Wed, 01 Sep 2010 04:41:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330559.htmlhttp://www.aygfsteel.com/jnbzwm/comments/330559.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330559.html#Feedback0http://www.aygfsteel.com/jnbzwm/comments/commentRss/330559.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/330559.html此问题在目中被发现Q经查看JDK源码(JDK1.6)QStringcȝpublic String substring(int beginIndex, int endIndex)的实现让我很意外?/p>

想重现这个场景很ҎQ请看代码?/p>

 1import java.util.ArrayList;
 2import java.util.List;
 3
 4public class LeakTest {
 5    public static void main(Stringargs) {
 6        List<String> handler = new ArrayList<String>();
 7        for(int i = 0; i < 100000; i++{
 8            Huge h = new Huge();
 9            handler.add(h.getSubString(15));
10        }

11    }

12}

13
14class Huge {
15    private String str = new String(new char[100000]);
16    public String getSubString(int begin, int end) {
17        return str.substring(begin, end);
18    }

19}

执行此代码结果:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

 

问题出在Hugecȝ getSubString ҎQ它调用了StringcȝsubstringҎ?/span>

来让我们看看 substring cȝ实现吧,JDK源码如下Q?/span>

 1    public String substring(int beginIndex, int endIndex) {
 2    if (beginIndex < 0{
 3        throw new StringIndexOutOfBoundsException(beginIndex);
 4    }

 5    if (endIndex > count) {
 6        throw new StringIndexOutOfBoundsException(endIndex);
 7    }

 8    if (beginIndex > endIndex) {
 9        throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
10    }

11    return ((beginIndex == 0&& (endIndex == count)) ? this :
12        new String(offset + beginIndex, endIndex - beginIndex, value);
13    }

再让我们接下来看?new String(offset + beginIndex, endIndex - beginIndex, value); 的实玎ͼ


1    // Package private constructor which shares value array for speed.
2    String(int offset, int count, char value[]) {
3    this.value = value;
4    this.offset = offset;
5    this.count = count;
6    }


char[] value 数组被共享了?/span>

 

在我们的main函数里的循环中,每@环一ơ后Q我们希望Huge对象被回Ӟ且释攑֮占有的内存?/span>

但实际上 private String str = new String(new char[100000]); 占有的内存ƈ不会被释放?/span>

因ؓ 我们通过 Huge cȝ getSubString Ҏ得到?String 对象q存?存在?/span>handler的列表中)Q?/span>

它虽然是 length 只有 4 的对象,却n有着 char[100000] 的空间?/span>

 

解决ҎQ?/span>

可以修改Huge cȝ getSubString Ҏ如下Q?/span>

1    public String getSubString(int begin, int end) {
2        return new String(str.substring(begin, end));
3    }

只要再套一个String的构造方法即可?/span>

 

至于Z么,看看JDK源码Q一看便知了。这里就不脓出来了?/span>

 

 

唉,以后写代码得多多心啊?/span>


----2010q?8?7?

本文为原创,Ƣ迎转蝲Q{载请注明出处BlogJava?/span>

]]>
Swing U程之SwingUtilities.invokeLater() http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330553.html??/dc:creator>??/author>Wed, 01 Sep 2010 04:05:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330553.htmlhttp://www.aygfsteel.com/jnbzwm/comments/330553.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330553.html#Feedback2http://www.aygfsteel.com/jnbzwm/comments/commentRss/330553.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/330553.html阅读全文

]]>
java实现数据库连接池http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330542.html??/dc:creator>??/author>Wed, 01 Sep 2010 03:36:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330542.htmlhttp://www.aygfsteel.com/jnbzwm/comments/330542.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330542.html#Feedback0http://www.aygfsteel.com/jnbzwm/comments/commentRss/330542.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/330542.html阅读全文

]]>
08q底 Sybase的一套笔试题Qjava版)http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330533.html??/dc:creator>??/author>Wed, 01 Sep 2010 03:16:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330533.htmlhttp://www.aygfsteel.com/jnbzwm/comments/330533.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330533.html#Feedback0http://www.aygfsteel.com/jnbzwm/comments/commentRss/330533.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/330533.html原帖Q?/p>

http://topic.csdn.net/u/20090113/17/5abc9a50-64dd-4277-af73-e8d2b762a469.html

 

我脓q来Q自己做一下?/p>

 

题目1Q?One team tries to buy several bottle of drinks for 27 athletes. In ABC store three empty bottles can be exchanged

with one new bottle of drinks. Which of the following numbers is the minimal one that the team should buy for the 27

athletes?

{:自己实现了一个,比较单的?br />
 1/** 
 2 * @author bzwm 
 3 *  
 4 */
 
 5public class BottleTest 
 6    public static void main(String[] args) 
 7        // 攄瓶子的栈 
 8        java.util.Stack<Object> emptyBottles = new java.util.Stack<Object>(); 
 9        // 买的饮料?nbsp;
10        int bottle = 0
11        // 喝过饮料的h?nbsp;
12        int drink = 0
13        // I饮料瓶?nbsp;
14        Object emptyBottle = new Object(); 
15        while (drink < 27
16            // 一个h喝过?nbsp;
17            drink++
18            // 把空瓶子攑֜栈中 
19            emptyBottles.push(emptyBottle); 
20            // 买的饮料数加1 
21            bottle++
22            // 如果I瓶子栈中的I瓶Cؓ3?nbsp;
23            if (emptyBottles.size() == 3
24                // 三个瓶子拿d店换饮料 
25                emptyBottles.pop(); 
26                emptyBottles.pop(); 
27                emptyBottles.pop(); 
28                // 一个h喝过饮料 
29                drink++
30                // 空瓶子再放在栈?nbsp;
31                emptyBottles.push(emptyBottle); 
32            }
 
33        }
 
34        System.out.println(bottle); 
35    }
 
36}

题目2Q?How can you create a listener class that receives events when the mouse is moved(single Answer)

A By extending MouseListener

B By implementing MouseListener
C By extending Mouse Motion Listener
D By implementing Mouse Motion Listener
E Either by extending Mouse Motion Listener  or extending MouseListener
F Either by implementing Mouse Motion Listener  or  implementing MouseListener

 

 

 

题目3Q?You are assign the task of building a panel containing a TextArea at the top, a label directly below it, and a button

directly below the label. If the three components are added directly to the panel, which layout manager can be panel use to

ensure that the TextArea absorbs all of the free vertical space when the parel is resized?

 

 

 

题目4Q?Which are not containers in Java?(Multiple answer)
A ScollPane
B Canvas
C Scrollbar
D Applet
E Dialog


 

 

题目5QYou need to store elements in a collection that 
guarantees that no duplicates are stored and all elements 
can be access in nature order, which interface provides 
that capability?

 

A java.uil.Map
B java.util.Collection
C java.util.List
D java.util.SortedSet
E java.util.SortedMap
F java.util.Set

 

 

 

题目6QWhat will happen when you attempt to compile and run this 
code?


abstract class Base{
  abstract public void myfunc();
public class Abs extends Base{
public static void main(String argv[])
{
  Abs a = new Abs();
  a.amethod();
}
public void amethod(){
  System.out.println("A method");;
}
}

A The code will compile and run, printing out the words "A 
method"
B The compiler will complain errors in Base class.
C The code will compile but complain at run time that the 
Base class has none abstract methods.
D The compiler will complain errors in Abs class

 

 

 

 

题目7Q?Description
import java.util.*;


public class Test
{
  private String value = null;
  public Test(String v)
  {
  value = v;
  }
  public boolean equals(Test o)
  {
  if(o==this) return true;
  if(o instanceof Test)
  {
  Test test =(Test) o;
  return value.equals(test.value);
  }
  return false;
  }
  public static void main(String[] args)
  {
  List list = new ArrayList();
  Test test1 = new Test("object");
  Test test2 = new Test("object");
  Test test3 = new Test("object");
  Object test4 = new Test("object");
  list.add(test1);

  System.out.println(list.contains(test2));
  System.out.println(test2.equals(test3));
  System.out.println(test3.equals(test4));

  }
}


 

 

 

题目8Q?
Which of the following is NOT true regarding to RuntimeException?
A RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtul
Machine.
B A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the

execution of the method but not caught.
C An RuntimeException is a subclass of Throwable that indicates serious problems that a reasonable application should not try
to catch.
D NullPointerException is one kind of RuntimeException.

 

 

 

 

题目9Q?Which of the following items demonstrates the key characteristics of Web 2.0

A Centralized
B User centered design
C Open
D Light Weight

 

 

 

 

题目10Q?When using the writeObject method to store the state of n  object, how can you protect sensitive data from being 
accessed in the stored object?
A Implement the Object as Exteralizable
B Declare the sensitive fields as private transient
C Declare the sensitive fields as static transient

D Declare the sensitive fields as protected transient


----2009q?1?2?br />

]]>
用Java设计一个程?扑ֈ一个字W串中对U字W串的个数【面试题?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330532.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Wed, 01 Sep 2010 03:13:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330532.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/330532.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330532.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/330532.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/330532.html</trackback:ping><description><![CDATA[<p>题目要求Q?/p> <p>用Java设计一个程?实现一个字W串的对UC?如字W串"effeghg",?ff","effe","ghg"q三个对U字W?所以返?. </p> <p> </p> <p>我实现的思\是遍历q个字符Ԍ</p> <p>先选定头位|ؓW一个字W,然后从最后向前遍历这个字W串Q?/p> <p>头尾两个字符相同Q则取中间字W串Q进行递归?/p> <p>递归l束后得到结果,</p> <p>l箋头向后?位,然后再从字符串最后向前遍历,</p> <p>如此循环Q当于头Ӟ退出最外层循环Q输出结果?/p> <p> </p> <p>具体实现Q?/p> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_0_29_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_29_Open_Text.style.display='none'; Codehighlighter1_0_29_Closed_Image.style.display='inline'; Codehighlighter1_0_29_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_0_29_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_29_Closed_Text.style.display='none'; Codehighlighter1_0_29_Open_Image.style.display='inline'; Codehighlighter1_0_29_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span id="Codehighlighter1_0_29_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_0_29_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> bzwm <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> *  <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_61_2048_Open_Image" onclick="this.style.display='none'; Codehighlighter1_61_2048_Open_Text.style.display='none'; Codehighlighter1_61_2048_Closed_Image.style.display='inline'; Codehighlighter1_61_2048_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_61_2048_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_61_2048_Closed_Text.style.display='none'; Codehighlighter1_61_2048_Open_Image.style.display='inline'; Codehighlighter1_61_2048_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> FindSymmetryStr </span><span id="Codehighlighter1_61_2048_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_61_2048_Open_Text"><span style="color: #000000">{ <br /> <img id="Codehighlighter1_68_142_Open_Image" onclick="this.style.display='none'; Codehighlighter1_68_142_Open_Text.style.display='none'; Codehighlighter1_68_142_Closed_Image.style.display='inline'; Codehighlighter1_68_142_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_68_142_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_68_142_Closed_Text.style.display='none'; Codehighlighter1_68_142_Open_Image.style.display='inline'; Codehighlighter1_68_142_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span id="Codehighlighter1_68_142_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_68_142_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />     * 扑և字符串中对称的子字符串的个数 <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />     * </span><span style="color: #808080">@param</span><span style="color: #008000"> orgStr <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />     * </span><span style="color: #808080">@return</span><span style="color: #008000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />     </span><span style="color: #008000">*/</span></span><span style="color: #000000"> <br /> <img id="Codehighlighter1_198_1853_Open_Image" onclick="this.style.display='none'; Codehighlighter1_198_1853_Open_Text.style.display='none'; Codehighlighter1_198_1853_Closed_Image.style.display='inline'; Codehighlighter1_198_1853_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_198_1853_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_198_1853_Closed_Text.style.display='none'; Codehighlighter1_198_1853_Open_Image.style.display='inline'; Codehighlighter1_198_1853_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> findSymmetryStr(String orgStr) </span><span id="Codehighlighter1_198_1853_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_198_1853_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">l果初始?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        </span><span style="color: #0000ff">int</span><span style="color: #000000"> count </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">当输入字W串不ؓnull且长度大?时进行查?否则直接q回0 </span><span style="color: #008000"><br /> <img id="Codehighlighter1_337_1822_Open_Image" onclick="this.style.display='none'; Codehighlighter1_337_1822_Open_Text.style.display='none'; Codehighlighter1_337_1822_Closed_Image.style.display='inline'; Codehighlighter1_337_1822_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_337_1822_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_337_1822_Closed_Text.style.display='none'; Codehighlighter1_337_1822_Open_Image.style.display='inline'; Codehighlighter1_337_1822_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (orgStr </span><span style="color: #000000">!=</span><span style="color: #000000"> </span><span style="color: #0000ff">null</span><span style="color: #000000"> </span><span style="color: #000000">&&</span><span style="color: #000000"> orgStr.length() </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">) </span><span id="Codehighlighter1_337_1822_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_337_1822_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">得到输入字符串的长度 </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">int</span><span style="color: #000000"> size </span><span style="color: #000000">=</span><span style="color: #000000"> orgStr.length(); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">字符串的头字W烦?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">int</span><span style="color: #000000"> head; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">字符串从后向前遍历时??字符索引,卛_前字W烦?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">int</span><span style="color: #000000"> current; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">字符串的头字W?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">char</span><span style="color: #000000"> hStr; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">字符串从后向前遍历时??字符 </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">char</span><span style="color: #000000"> cStr; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000">从前开始遍历字W串 </span><span style="color: #008000"><br /> <img id="Codehighlighter1_700_1811_Open_Image" onclick="this.style.display='none'; Codehighlighter1_700_1811_Open_Text.style.display='none'; Codehighlighter1_700_1811_Closed_Image.style.display='inline'; Codehighlighter1_700_1811_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_700_1811_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_700_1811_Closed_Text.style.display='none'; Codehighlighter1_700_1811_Open_Image.style.display='inline'; Codehighlighter1_700_1811_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">for</span><span style="color: #000000"> (head </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; head </span><span style="color: #000000"><</span><span style="color: #000000"> size; head</span><span style="color: #000000">++</span><span style="color: #000000">) </span><span id="Codehighlighter1_700_1811_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_700_1811_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                </span><span style="color: #008000">//</span><span style="color: #008000">取得头字W?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                hStr </span><span style="color: #000000">=</span><span style="color: #000000"> orgStr.charAt(head); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                </span><span style="color: #008000">//</span><span style="color: #008000">指向输入字符串的最?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                current </span><span style="color: #000000">=</span><span style="color: #000000"> size </span><span style="color: #000000">-</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                </span><span style="color: #008000">//</span><span style="color: #008000">当尾字符索引{于头字W烦引时退出@?nbsp;</span><span style="color: #008000"><br /> <img id="Codehighlighter1_917_1796_Open_Image" onclick="this.style.display='none'; Codehighlighter1_917_1796_Open_Text.style.display='none'; Codehighlighter1_917_1796_Closed_Image.style.display='inline'; Codehighlighter1_917_1796_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_917_1796_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_917_1796_Closed_Text.style.display='none'; Codehighlighter1_917_1796_Open_Image.style.display='inline'; Codehighlighter1_917_1796_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">                </span><span style="color: #0000ff">while</span><span style="color: #000000"> (current </span><span style="color: #000000">></span><span style="color: #000000"> head) </span><span id="Codehighlighter1_917_1796_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_917_1796_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                    </span><span style="color: #008000">//</span><span style="color: #008000">取得֭W?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                    cStr </span><span style="color: #000000">=</span><span style="color: #000000"> orgStr.charAt(current); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                    </span><span style="color: #008000">//</span><span style="color: #008000">如果头尾字符相等,则l判?nbsp;</span><span style="color: #008000"><br /> <img id="Codehighlighter1_1077_1644_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1077_1644_Open_Text.style.display='none'; Codehighlighter1_1077_1644_Closed_Image.style.display='inline'; Codehighlighter1_1077_1644_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1077_1644_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1077_1644_Closed_Text.style.display='none'; Codehighlighter1_1077_1644_Open_Image.style.display='inline'; Codehighlighter1_1077_1644_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">                    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (hStr </span><span style="color: #000000">==</span><span style="color: #000000"> cStr) </span><span id="Codehighlighter1_1077_1644_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1077_1644_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                        </span><span style="color: #008000">//</span><span style="color: #008000">取出头尾中间的子字符?对其q行分析 </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                        String newStr </span><span style="color: #000000">=</span><span style="color: #000000"> orgStr.substring(head </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">, current); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                        </span><span style="color: #008000">//</span><span style="color: #008000">如果此子字符串的长度大于1,则进行递归 </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (newStr.length() </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">) <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                            </span><span style="color: #008000">//</span><span style="color: #008000">递归得到此子字符串中对称的字W串个数 </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                            count </span><span style="color: #000000">+=</span><span style="color: #000000"> findSymmetryStr(newStr); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                        </span><span style="color: #008000">//</span><span style="color: #008000">如果此子字符串只?个或0个字W?则表明原头尾字符和此单个字符l成对称字符?nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                        </span><span style="color: #0000ff">else</span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                            count</span><span style="color: #000000">++</span><span style="color: #000000">; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                        </span><span style="color: #008000">//</span><span style="color: #008000">尾字符索引向前??nbsp;</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">                        current</span><span style="color: #000000">--</span><span style="color: #000000">; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />                    }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                    </span><span style="color: #008000">//</span><span style="color: #008000">如果头尾字符不相{?则将֭W烦引向前推1?nbsp;</span><span style="color: #008000"><br /> <img id="Codehighlighter1_1718_1777_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1718_1777_Open_Text.style.display='none'; Codehighlighter1_1718_1777_Closed_Image.style.display='inline'; Codehighlighter1_1718_1777_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1718_1777_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1718_1777_Closed_Text.style.display='none'; Codehighlighter1_1718_1777_Open_Image.style.display='inline'; Codehighlighter1_1718_1777_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">                    </span><span style="color: #0000ff">else</span><span style="color: #000000"> </span><span id="Codehighlighter1_1718_1777_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1718_1777_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                        current</span><span style="color: #000000">--</span><span style="color: #000000">; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />                    }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />                }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />            }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> count; <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #008000">//</span><span style="color: #008000">试E序 </span><span style="color: #008000"><br /> <img id="Codehighlighter1_1912_2045_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1912_2045_Open_Text.style.display='none'; Codehighlighter1_1912_2045_Closed_Image.style.display='inline'; Codehighlighter1_1912_2045_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1912_2045_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1912_2045_Closed_Text.style.display='none'; Codehighlighter1_1912_2045_Open_Image.style.display='inline'; Codehighlighter1_1912_2045_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String args[]) </span><span id="Codehighlighter1_1912_2045_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1912_2045_Open_Text"><span style="color: #000000">{ <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">int</span><span style="color: #000000"> count </span><span style="color: #000000">=</span><span style="color: #000000"> findSymmetryStr(</span><span style="color: #000000">"</span><span style="color: #000000">cddcbcbeffeghg</span><span style="color: #000000">"</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000"> </span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">symmetry string count is : </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> count); <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"> <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <br /> <br /> ----2008q?2?2? <img src ="http://www.aygfsteel.com/jnbzwm/aggbug/330532.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2010-09-01 11:13 <a href="http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330532.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>利用Calendar输出指定q䆾的全q日?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330528.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Wed, 01 Sep 2010 03:09:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330528.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/330528.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330528.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/330528.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/330528.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img id="Codehighlighter1_0_26_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_26_Open_Text.style.display='none'; Codehighlighter1_0_26_Closed_Image.style.display='inline'; Codehighlighter1_0_26_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_0_26_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_0_26_Closed_Text.style.display='none'; Codehighlighter1_0_26_Open_Image.style.display='inline'; Codehighlighter1_0_26_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span id="Codehighlighter1_0_26_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff">/** */</span><span id="Codehighlighter1_0_26_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * </span><span style="color: #808080">@author</span><span style="color: #008000"> bzwm<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /> * <br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.BufferedReader;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.IOException;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.io.InputStreamReader;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.Calendar;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.GregorianCalendar;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_211_521_Open_Image" onclick="this.style.display='none'; Codehighlighter1_211_521_Open_Text.style.display='none'; Codehighlighter1_211_521_Closed_Image.style.display='inline'; Codehighlighter1_211_521_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_211_521_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_211_521_Closed_Text.style.display='none'; Codehighlighter1_211_521_Open_Image.style.display='inline'; Codehighlighter1_211_521_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> CalendarTest </span><span id="Codehighlighter1_211_521_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_211_521_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_275_519_Open_Image" onclick="this.style.display='none'; Codehighlighter1_275_519_Open_Text.style.display='none'; Codehighlighter1_275_519_Closed_Image.style.display='inline'; Codehighlighter1_275_519_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_275_519_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_275_519_Closed_Text.style.display='none'; Codehighlighter1_275_519_Open_Image.style.display='inline'; Codehighlighter1_275_519_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> IOException </span><span id="Codehighlighter1_275_519_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_275_519_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        BufferedReader in </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> BufferedReader(</span><span style="color: #0000ff">new</span><span style="color: #000000"> InputStreamReader(System.in));<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.print(</span><span style="color: #000000">"</span><span style="color: #000000">误入一个年份:</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        String years </span><span style="color: #000000">=</span><span style="color: #000000"> in.readLine();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        CalendarPrinter cp </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> CalendarPrinter(years);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        cp.printCal();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_546_2392_Open_Image" onclick="this.style.display='none'; Codehighlighter1_546_2392_Open_Text.style.display='none'; Codehighlighter1_546_2392_Closed_Image.style.display='inline'; Codehighlighter1_546_2392_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_546_2392_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_546_2392_Closed_Text.style.display='none'; Codehighlighter1_546_2392_Open_Image.style.display='inline'; Codehighlighter1_546_2392_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /></span><span style="color: #0000ff">class</span><span style="color: #000000"> CalendarPrinter </span><span id="Codehighlighter1_546_2392_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_546_2392_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> year;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">final</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000"> monthCount </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">12</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_660_844_Open_Image" onclick="this.style.display='none'; Codehighlighter1_660_844_Open_Text.style.display='none'; Codehighlighter1_660_844_Closed_Image.style.display='inline'; Codehighlighter1_660_844_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_660_844_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_660_844_Closed_Text.style.display='none'; Codehighlighter1_660_844_Open_Image.style.display='inline'; Codehighlighter1_660_844_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> CalendarPrinter(String years) </span><span id="Codehighlighter1_660_844_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_660_844_Open_Text"><span style="color: #000000">{<br /> <img id="Codehighlighter1_702_798_Open_Image" onclick="this.style.display='none'; Codehighlighter1_702_798_Open_Text.style.display='none'; Codehighlighter1_702_798_Closed_Image.style.display='inline'; Codehighlighter1_702_798_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_702_798_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_702_798_Closed_Text.style.display='none'; Codehighlighter1_702_798_Open_Image.style.display='inline'; Codehighlighter1_702_798_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #000000">!</span><span style="color: #000000">years.matches(</span><span style="color: #000000">"</span><span style="color: #000000">\\d{4}</span><span style="color: #000000">"</span><span style="color: #000000">)) </span><span id="Codehighlighter1_702_798_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_702_798_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">year that inputted is illagel.</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        year </span><span style="color: #000000">=</span><span style="color: #000000"> Integer.parseInt(years);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_874_1178_Open_Image" onclick="this.style.display='none'; Codehighlighter1_874_1178_Open_Text.style.display='none'; Codehighlighter1_874_1178_Closed_Image.style.display='inline'; Codehighlighter1_874_1178_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_874_1178_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_874_1178_Closed_Text.style.display='none'; Codehighlighter1_874_1178_Open_Image.style.display='inline'; Codehighlighter1_874_1178_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> printCal() </span><span id="Codehighlighter1_874_1178_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_874_1178_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> construct d as current date</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        GregorianCalendar gCal </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> GregorianCalendar();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">set year</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        gCal.set(Calendar.YEAR, year);<br /> <img id="Codehighlighter1_1089_1172_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1089_1172_Open_Text.style.display='none'; Codehighlighter1_1089_1172_Closed_Image.style.display='inline'; Codehighlighter1_1089_1172_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1089_1172_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1089_1172_Closed_Text.style.display='none'; Codehighlighter1_1089_1172_Open_Image.style.display='inline'; Codehighlighter1_1089_1172_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> month </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">; month </span><span style="color: #000000"><</span><span style="color: #000000"> monthCount; month</span><span style="color: #000000">++</span><span style="color: #000000">) </span><span id="Codehighlighter1_1089_1172_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1089_1172_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            gCal.set(Calendar.MONTH, month);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            printOut(gCal);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_1221_2390_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1221_2390_Open_Text.style.display='none'; Codehighlighter1_1221_2390_Closed_Image.style.display='inline'; Codehighlighter1_1221_2390_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1221_2390_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1221_2390_Closed_Text.style.display='none'; Codehighlighter1_1221_2390_Open_Image.style.display='inline'; Codehighlighter1_1221_2390_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">private</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> printOut(Calendar cal) </span><span id="Codehighlighter1_1221_2390_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1221_2390_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">int</span><span style="color: #000000"> month </span><span style="color: #000000">=</span><span style="color: #000000"> cal.get(Calendar.MONTH);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> set cal to start date of the month</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        cal.set(Calendar.DAY_OF_MONTH, </span><span style="color: #000000">1</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">int</span><span style="color: #000000"> weekday </span><span style="color: #000000">=</span><span style="color: #000000"> cal.get(Calendar.DAY_OF_WEEK);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> print heading</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">Sun Mon Tue Wed Thu Fri Sat</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> indent first line of calendar</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        </span><span style="color: #0000ff">for</span><span style="color: #000000"> (</span><span style="color: #0000ff">int</span><span style="color: #000000"> i </span><span style="color: #000000">=</span><span style="color: #000000"> Calendar.SUNDAY; i </span><span style="color: #000000"><</span><span style="color: #000000"> weekday; i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            System.out.print(</span><span style="color: #000000">"</span><span style="color: #000000">    </span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img id="Codehighlighter1_1645_2159_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1645_2159_Open_Text.style.display='none'; Codehighlighter1_1645_2159_Closed_Image.style.display='inline'; Codehighlighter1_1645_2159_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_1645_2159_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_1645_2159_Closed_Text.style.display='none'; Codehighlighter1_1645_2159_Open_Image.style.display='inline'; Codehighlighter1_1645_2159_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />        </span><span style="color: #0000ff">do</span><span style="color: #000000"> </span><span id="Codehighlighter1_1645_2159_Closed_Text" style="border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_1645_2159_Open_Text"><span style="color: #000000">{<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000"> print day</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">int</span><span style="color: #000000"> day </span><span style="color: #000000">=</span><span style="color: #000000"> cal.get(Calendar.DAY_OF_MONTH);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (day </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                System.out.print(</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> day </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #0000ff">else</span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                System.out.print(</span><span style="color: #000000">"</span><span style="color: #000000">  </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> day </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000"> start a new line after every Saturday</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            </span><span style="color: #0000ff">if</span><span style="color: #000000"> (weekday </span><span style="color: #000000">==</span><span style="color: #000000"> Calendar.SATURDAY)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />                System.out.println();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            </span><span style="color: #008000">//</span><span style="color: #008000"> advance d to the next day</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">            cal.add(Calendar.DAY_OF_MONTH, </span><span style="color: #000000">1</span><span style="color: #000000">);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            weekday </span><span style="color: #000000">=</span><span style="color: #000000"> cal.get(Calendar.DAY_OF_WEEK);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />        }</span></span><span style="color: #000000"> </span><span style="color: #0000ff">while</span><span style="color: #000000"> (cal.get(Calendar.MONTH) </span><span style="color: #000000">==</span><span style="color: #000000"> month);<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> the loop exits when d is day 1 of the next month<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000"> print final end of line if necessary</span><span style="color: #008000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        </span><span style="color: #0000ff">if</span><span style="color: #000000"> (weekday </span><span style="color: #000000">!=</span><span style="color: #000000"> Calendar.SUNDAY)<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />            System.out.println();<br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" />    }</span></span><span style="color: #000000"><br /> <img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span></div> <br /> ----2008q?2?1? <img src ="http://www.aygfsteel.com/jnbzwm/aggbug/330528.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2010-09-01 11:09 <a href="http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330528.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>l上一文章,用栈来实玎ͼ按照用户输入的ruleQ经qƈ、交、差q算后,输出字符串结果?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330523.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Wed, 01 Sep 2010 03:01:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330523.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/330523.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330523.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/330523.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/330523.html</trackback:ping><description><![CDATA[     摘要: 废话不说了, 文gQ?A{1,2,3,4,5,6} B{7,4,5,6,8} C{2,3,12,14,4,11}   试时输入到控制台的字符串ؓQ?C+B-(A*(C-A))+B   l果Q?2 3 12 14 4 11 7 8 1 5 6   自己了一下,是正的Q?  代码如下Q注释也写的蛮多的:  &nbs...  <a href='http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330523.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jnbzwm/aggbug/330523.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2010-09-01 11:01 <a href="http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330523.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一道笔试题Q按照用戯入的ruleQ经qƈ、交、差q算后,输出字符串结果?/title><link>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330520.html</link><dc:creator>??/dc:creator><author>??/author><pubDate>Wed, 01 Sep 2010 02:56:00 GMT</pubDate><guid>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330520.html</guid><wfw:comment>http://www.aygfsteel.com/jnbzwm/comments/330520.html</wfw:comment><comments>http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330520.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jnbzwm/comments/commentRss/330520.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jnbzwm/services/trackbacks/330520.html</trackback:ping><description><![CDATA[     摘要: 今天在CSDN看到一个笔试题Q觉得蛮有意思的Q?题目如下Q?从事先写好的Input.txt文g中读取数Q? Input.txt 内容 A{13Q?Q?Q?0Q?0Q?0} B{1Q?Q?4Q?Q?} C{2Q?Q?2Q?3Q?4Q?1} 用户在键盘随意敲?..例如((A*B))+B-C,((C+B)*A)-B期中+,*Q?,分别代表集合的ƈ交差q算Q控制台打印输出?&n...  <a href='http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330520.html'>阅读全文</a><img src ="http://www.aygfsteel.com/jnbzwm/aggbug/330520.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jnbzwm/" target="_blank">??/a> 2010-09-01 10:56 <a href="http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/330520.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java socket/swing聊天E序http://www.aygfsteel.com/jnbzwm/archive/2010/09/01/J2SE_Swing_Socket.html??/dc:creator>??/author>Wed, 01 Sep 2010 02:40:00 GMThttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/J2SE_Swing_Socket.htmlhttp://www.aygfsteel.com/jnbzwm/comments/330512.htmlhttp://www.aygfsteel.com/jnbzwm/archive/2010/09/01/J2SE_Swing_Socket.html#Feedback0http://www.aygfsteel.com/jnbzwm/comments/commentRss/330512.htmlhttp://www.aygfsteel.com/jnbzwm/services/trackbacks/330512.html阅读全文

]]>
վ֩ģ壺 | ̨| | | | Ľ| ǿ| | | ˮ| | | | ˰| ߷| ͳ| | ˹| Ӱ| | | ԭ| Դ| | | | 㶫ʡ| | | ɽ| | Ҷ| ľ| ţ| | dz| û| | | | ƽ|