【其它话题】求助一段java code
所在版块:心情闲聊 发贴时间:2012-08-16 14:53

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
<!--[if gte mso 9]><xml> <o:documentproperties> <o:author>Bruce Eckel</o:author> <o:version>14.00</o:version> </o:documentproperties> <o:officedocumentsettings> <o:allowpng /> </o:officedocumentsettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:view> <w:zoom>0</w:zoom> <w:trackmoves /> <w:trackformatting /> <w:punctuationkerning /> <w:validateagainstschemas /> <w:saveifxmlinvalid>false</w:saveifxmlinvalid> <w:ignoremixedcontent>false</w:ignoremixedcontent> <w:alwaysshowplaceholdertext>false</w:alwaysshowplaceholdertext> <w:donotpromoteqf /> <w:lidthemeother>EN-SG</w:lidthemeother> <w:lidthemeasian>ZH-CN</w:lidthemeasian> <w:lidthemecomplexscript>X-NONE</w:lidthemecomplexscript> <w:compatibility> <w:breakwrappedtables /> <w:snaptogridincell /> <w:wraptextwithpunct /> <w:useasianbreakrules /> <w:dontgrowautofit /> <w:splitpgbreakandparamark /> <w:enableopentypekerning /> <w:dontflipmirrorindents /> <w:overridetablestylehps /> <w:usefelayout /> </w:compatibility> <m:mathpr> <m:mathfont m:val="Cambria Math" /> <m:brkbin m:val="before" /> <m:brkbinsub m:val="&#45;-" /> <m:smallfrac m:val="off" /> <m:dispdef /> <m:lmargin m:val="0" /> <m:rmargin m:val="0" /> <m:defjc m:val="centerGroup" /> <m:wrapindent m:val="1440" /> <m:intlim m:val="subSup" /> <m:narylim m:val="undOvr" /> </m:mathpr></w:worddocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"> <w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal" /> <w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 2" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 3" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 4" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 5" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 6" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 7" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 8" /> <w:lsdexception locked="false" priority="9" qformat="true" name="heading 9" /> <w:lsdexception locked="false" priority="39" name="toc 1" /> <w:lsdexception locked="false" priority="39" name="toc 2" /> <w:lsdexception locked="false" priority="39" name="toc 3" /> <w:lsdexception locked="false" priority="39" name="toc 4" /> <w:lsdexception locked="false" priority="39" name="toc 5" /> <w:lsdexception locked="false" priority="39" name="toc 6" /> <w:lsdexception locked="false" priority="39" name="toc 7" /> <w:lsdexception locked="false" priority="39" name="toc 8" /> <w:lsdexception locked="false" priority="39" name="toc 9" /> <w:lsdexception locked="false" priority="35" qformat="true" name="caption" /> <w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title" /> <w:lsdexception locked="false" priority="1" name="Default Paragraph Font" /> <w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle" /> <w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong" /> <w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis" /> <w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid" /> <w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text" /> <w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1" /> <w:lsdexception locked="false" unhidewhenused="false" name="Revision" /> <w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph" /> <w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote" /> <w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5" /> <w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6" /> <w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6" /> <w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6" /> <w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6" /> <w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6" /> <w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6" /> <w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6" /> <w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6" /> <w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6" /> <w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6" /> <w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6" /> <w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6" /> <w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6" /> <w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6" /> <w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis" /> <w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis" /> <w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference" /> <w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference" /> <w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title" /> <w:lsdexception locked="false" priority="37" name="Bibliography" /> <w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading" /> </w:latentstyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} </style> <![endif]-->

小弟目前刚刚上手java, 看到think in java里有这一段code,如下:

//: reusing/SprinklerSystem.java

// Composition for code reuse.

class WaterSource {

private String s;

WaterSource() {

System.out.println("WaterSource()");

s = "Constructed";

}

public String toString() { return s; }

}


public class SprinklerSystem {

private String valve1, valve2, valve3, valve4;

private WaterSource source = new WaterSource();

private int i;

private float f;

public String toString() {

return

"valve1 = " + valve1 + " " +

"valve2 = " + valve2 + " " +

"valve3 = " + valve3 + " " +

"valve4 = " + valve4 + "\n" +

"i = " + i + " " + "f = " + f + " " +

"source = " + source;

}

public static void main(String[] args) {

SprinklerSystem sprinklers = new SprinklerSystem();

System.out.println(sprinklers);

}

}

 

/* Output:

WaterSource()

valve1 = null valve2 = null valve3 = null valve4 = null

i = 0 f = 0.0 source = Constructed

*///:


实在不懂为什么最后output里的source=Constructed. 特地前来请教,在线等。

.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

 相关帖子 我要回复↙ ↗回到正文
【其它话题】求助一段java code about:home   (22533 bytes , 555reads )
不知道有没解释对 月之女祭司   (548 bytes , 189reads )
+1 yuwu   (16 bytes , 98reads )
谢谢 很清楚 about:home   (518 bytes , 106reads )
java中对String overload了'+'这个运算符 zhj   (56 bytes , 142reads )
这些都可以在网上查到的 Pokka   (160 bytes , 101reads )
好像理解错你的问题了 Pokka   (162 bytes , 118reads )
谢谢 @pokka @zhj @月之女祭祀 明白了 about:home   (0 bytes , 101reads )
我也不是很清楚 求高手啊。。。。 月之女祭司   (119 bytes , 116reads )
先送些分给你~~~ 小妖霖霖   (0 bytes , 114reads )
前面那一大段吓到我了…… 小妖霖霖   (25 bytes , 103reads )
学好java来华新抓虫。。。。 about:home   (0 bytes , 103reads )
华新好像是PHP的。。。。。。。。 济癫   (0 bytes , 122reads )