{"id":16,"date":"2009-04-17T10:41:40","date_gmt":"2009-04-17T02:41:40","guid":{"rendered":"http:\/\/www.fujiangyun.com.cn\/?p=16"},"modified":"2009-04-17T10:41:40","modified_gmt":"2009-04-17T02:41:40","slug":"%e6%a2%81%e6%a0%8b%e7%94%a8java%e5%86%99%e7%9a%84%e7%94%bb%e5%9c%86%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.fujiangyun.com\/blog\/?p=16","title":{"rendered":"\u6881\u680b\u7528java\u5199\u7684\u753b\u5706\u7b97\u6cd5"},"content":{"rendered":"<p class=\"p0\" style=\"margin-top: 0pt; margin-bottom: 0pt;\">public class PrintCircle {<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span><span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  \/**<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>   * @param args<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>   *\/<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  public static void main(String[] args) {<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    int n=1000;\/\/n\u8d8a\u5927\uff0c\u624d\u80fd\u8d8a\u63a5\u8fd1\u5706<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    PrintCircle p = new PrintCircle();<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    for(int i=0;i&lt;2*n;i++){<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      p.printPoint(n,i);<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  <span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  private int[] getXFromY(int y,int n)\/\/n\u4e3a\u534a\u5f84\uff0cy&lt;2n,\u8fd4\u56de2\u4e2ax<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  {<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    if(y&lt;=n){\/\/\u4e0a\u534a\u4fa7<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x1=n-(int)Math.sqrt(n*n-(n-y)*(n-y));<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x2=(int)Math.sqrt(n*n-(n-y)*(n-y))+n;<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      return new int[]{x1,x2};<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    else if(y&lt;=2*n){\/\/\u4e0b\u534a\u4fa7<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x1=n-(int)Math.sqrt(n*n-(n-y)*(n-y));<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x2=(int)Math.sqrt(n*n-(n-y)*(n-y))+n;<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      return new int[]{x1,x2};<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    return null;<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  <span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  private void printPoint(int n,int y){\/\/\u534a\u5f84n,\u5728(x,y)\u7684\u4f4d\u7f6e\u6253\u5370\u4e00\u4e2a*<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x1=getXFromY(y,n)[0];<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      int x2=getXFromY(y,n)[1];<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>      for(int i=0;i&lt;=2*n;i++){<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>        if(i==2*n) System.out.println(&#8220;n&#8221;);<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>        if(i==x1||i==x2) System.out.print(&#8220;*&#8221;);<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>        else System.out.print(&#8221; &#8220;);<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>    }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>  }<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span>}<span style=\"font-family: '\u5bf0\ue1bf\u848b\u95c6\u5474\u7ca6'; background: #eeeeee; color: #333333; font-size: 9pt; mso-spacerun: 'yes';\"><br \/>\n<\/span><\/p>\n<p><!--EndFragment--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6881\u680b\u5199\u7684\u4e00\u4e2aJAVA\u7248\u7684\u753b\u5706\u7b97\u6cd5<br \/>\npublic class PrintCircle {<\/p>\n<p>  \/**<br \/>\n   * @param args<br \/>\n   *\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[16,18,46],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-4","tag-java","tag-ldsea","tag-46"],"_links":{"self":[{"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16"}],"version-history":[{"count":0,"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fujiangyun.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}