{"id":4901,"date":"2024-10-07T09:01:03","date_gmt":"2024-10-07T01:01:03","guid":{"rendered":""},"modified":"2024-10-07T09:01:03","modified_gmt":"2024-10-07T01:01:03","slug":"\u6d59\u5927\u7fc1\u51ef\u8001\u5e08Java\u8bfe\u5802\u5b66\u4e60\u8bb0\u5f55\uff08\u7b2c\u4e09\u5468\uff09","status":"publish","type":"post","link":"https:\/\/mushiming.com\/4901.html","title":{"rendered":"\u6d59\u5927\u7fc1\u51ef\u8001\u5e08Java\u8bfe\u5802\u5b66\u4e60\u8bb0\u5f55\uff08\u7b2c\u4e09\u5468\uff09"},"content":{"rendered":"
\u63a5\u7740\u7b2c\u4e8c\u5468\u81ea\u52a8\u552e\u7968\u673a\u7684\u6848\u4f8b\uff0c\u73b0\u5728\u4e3a\u4e86\u5b9e\u73b0\u552e\u7968\u673a\u6301\u7eed\u5de5\u4f5c\uff0c\u5c31\u5c06\u5b9e\u73b0\u552e\u7968\u529f\u80fd\u7684\u4ee3\u7801\u6bb5\u653e\u5165\u5faa\u73af\u7ed3\u6784\uff0c\u8fd9\u6837\u4fbf\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u552e\u7968\u673a\u7684\u673a\u5236\u3002<\/p>\n
\u5b9e\u73b0\u5faa\u73af<\/span>\u4ee3\u7801<\/strong>\uff1a<\/p>\n \u4ee3\u7801\u89e3\u91ca\uff1a<\/strong>\u5f15\u5165\u7684\u53d8\u91cfbalance\u662f\u4e3a\u4e86\u7b2c\u4e00\u6b21\u6295\u5165\u94b1\u4e0d\u591f\uff0c\u7b2c\u4e8c\u6b21\u8fdb\u884c\u590d\u6295\u7528\u6765\u76f8\u52a0\u7684\uff0c\u5728if\u5224\u65ad\u8bed\u53e5\u4e2d\u7528balance\u4ee3\u66ffamount<\/span>\uff0c\u4ece\u800c\u907f\u514d\u9996\u6b21\u6295\u5165\u94b1\u5e01\u4e0d\u591f\u518d\u6295\u94b1\u5e01\u7a0b\u5e8f\u4e0d\u8fd0\u884c\u7684\u60c5\u51b5\u51fa\u73b0<\/span>\u3002\u540c\u65f6\u5728\u4e00\u6b21\u5faa\u73af\u529f\u80fd\u6267\u884c\u7ed3\u675f\u540e\uff0c\u4e5f\u5c31\u662f\u627e\u96f6\u529f\u80fd\u5b8c\u6210\u540e\uff0c\u5bf9balance\u4f59\u989d\u8fdb\u884c\u6e05\u96f6\u5de5\u4f5c<\/span>\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u8fdb\u5165\u4e0b\u4e00\u6b21\u5faa\u73af\u7684\u5f71\u54cd\u3002<\/p>\n \u7a0b\u5e8f\u8981\u8bfb\u5165\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u7136\u540e\u8f93\u51fa\u8fd9\u4e2a\u6574\u6570\u7684\u4f4d\u6570\u3002\u5982\uff1a<\/p>\n \u8f93\u5165\uff1a352 <\/p>\n \u8f93\u51fa\uff1a3<\/p>\n \u4ee3\u7801\u5b9e\u73b0\uff1a<\/strong><\/p>\n \u8fd0\u884c\u7ed3\u679c\uff1a<\/strong><\/p>\n 352<\/p>\n \u4f4d\u6570\u4e3a\uff1a3<\/p>\n<\/blockquote>\n \u89e3\u91ca\u4ee3\u7801\uff1a<\/strong><\/p>\n \u5728\u89e3\u91ca\u4ee3\u7801\u4e4b\u524d\uff0c\u5148\u8bf4\u4e00\u8bf4\u8fd9\u9053\u9898\u7684\u89e3\u6cd5\u3002<\/p>\n \u8ba1\u7b97\u673a\u5982\u4f55\u6765\u8ba1\u6570\u5462\uff1f<\/span>\u6709\u4e00\u4e2a\u5f88\u5927\u7684\u6570\uff0c\u90a3\u4e48\u6211\u4eec\u4ece\u53f3\u5f80\u5de6\u5bf9\u5b83\u8fdb\u884c\u53d6\u4f59\u8ba1\u7b97\uff0c\u5982352\uff0c\u9996\u5148\u4ee4352\/<\/p>\n while(number>0)<\/span>\uff0c\u5982\u679cnumber>0\u6761\u4ef6\u6210\u7acb\uff0c\u90a3\u4e48\u5c31\u8fdb\u884c{}\u5185\u7684\u4ee3\u7801\uff0c\u672c\u6765\u5e94\u8be5\u4f7f\u7528if\u8bed\u53e5\u7684\uff0c\u4f46\u56e0\u4e3a\u6211\u4eec\u60f3\u8ba9\u8fd9\u4e2a{}\u5185\u7684\u8ba1\u7b97\u4e00\u76f4\u505a\u4e0b\u53bb<\/span>\uff0c\u76f4\u5230number<=0\u4e3a\u6b62\uff0c\u56e0\u6b64\u6211\u4eec\u5e94\u5f53\u4f7f\u7528while\u5faa\u73af<\/span>\u7ed3\u6784\u3002<\/p>\n 1.\u5b9a\u4e49\uff1a<\/strong>\u5c06\u201cwhile\u201d\u7ffb\u8bd1\u6210\u201c\u5f53\u201d\uff0c\u4e00\u4e2awhile\u5faa\u73af\u5373\uff1a\u5f53\u6761\u4ef6\u6ee1\u8db3\uff0c\u91cd\u590d\u6267\u884c\u5faa\u73af\u4f53\u5185\u7684\u8bed\u53e5\u3002<\/strong><\/p>\n 2.\u533a\u5206\uff1a<\/strong>if\u6761\u4ef6\u8bed\u53e5\u8fdb\u884c\u4e00\u6b21\uff0c\u4f7f\u7528while\u6761\u4ef6\u6ee1\u8db3\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4e00\u76f4\u8fdb\u884c\uff0c\u76f4\u81f3\u4e0d\u518d\u6ee1\u8db3\u6761\u4ef6\u3002<\/p>\n \u4e3e\u4f8b\uff1a<\/p>\n \u8bf4\u660e\uff1a<\/strong><\/span>\u5728\u5927\u62ec\u53f7{}\u91cc\u9762\u7684\u5185\u5bb9\u53eb\u505a\u5faa\u73af\u4f53\uff1b\u5728\u5706\u62ec\u53f7\uff08\uff09\u91cc\u7684\u53eb\u505a\u6761\u4ef6\u3002<\/span><\/p>\n \u6ce8\u610f\uff1a<\/strong><\/p>\n \u2460<\/strong>\u5728\u5faa\u73af\u4f53\u5185\u8981\u6709\u6539\u53d8\u6761\u4ef6\u7684\u673a\u4f1a\uff0c\u5426\u5219while\u5c06\u4f1a\u53d8\u6210\u6b7b\u5faa\u73af\u4e00\u76f4\u505a\u4e0b\u53bb\u3002<\/p>\n \u2461\u6267\u884cwhile\u5faa\u73af<\/span>\u524d\uff0c\u9996\u5148\u5224\u65ad\u6761\u4ef6\u662f\u5426\u6ee1\u8db3<\/span>\uff0c\u6240\u4ee5\u5b58\u5728\u5faa\u73af\u4e00\u6b21\u4e5f\u6ca1\u88ab\u6267\u884c\u7684\u60c5\u51b5<\/span>\u3002<\/p>\n \u2462\u6761\u4ef6\u6210\u7acb\u662f\u5faa\u73af\u7ee7\u7eed\u7684\u524d\u63d0\u3002<\/p>\n \u4eba\u8111\u6a21\u62df\u8ba1\u7b97\u673a<\/span>\uff08\u4f7f\u7528\u201c\u53d8\u91cf\u8868\u683c\u201d\uff0c\u7eb8\u4e0a\u4e00\u6b65\u4e00\u6b65\u5199\u4e0b\u4ee3\u7801\u8fd0\u884c\u7ed3\u679c\uff09<\/p>\n \u8c03\u8bd5<\/span>\uff08\u5728\u7a0b\u5e8f\u9002\u5f53\u7684\u5730\u65b9\u63d2\u5165\u8f93\u51fa\u6765\u663e\u793a\u53d8\u91cf\u7684\u5185\u5bb9\uff09<\/p>\n Debug<\/span>\uff08\u52a0\u65ad\u70b9\uff09<\/p>\n \u8c03\u8bd5\u4e3e\u4f8b<\/strong>\uff08\u6570\u6570\u5b57\u7684\u4ee3\u7801\uff09<\/p>\n \u8fd0\u884c\u7ed3\u679c\uff1a<\/strong><\/p>\n 352<\/p>\n number=35;count=1<\/p>\n number=3;count=2<\/p>\n number=0;count=3<\/p>\n \u4f4d\u6570\u4e3a\uff1a3<\/p>\n<\/blockquote>\n \u53e6\u5916\uff0c\u5f53\u6211\u4eec\u7684\u7a0b\u5e8f\u5b8c\u6210\u540e\uff0c\u901a\u5e38\u9700\u8981\u201c\u9a8c\u8bc1<\/strong><\/span>\u201d\uff0c\u6d4b\u8bd5\u7a0b\u5e8f\u5e38\u4f7f\u7528\u8fb9\u754c\u6570\u636e<\/span>\uff0c\u5982\u6709\u6548\u8303\u56f4\u4e24\u7aef\u7684\u6570\u636e\u3001\u7279\u6b8a\u7684\u500d\u6570<\/span>\u7b49\u7b49\u3002&#x<\/p>\n","protected":false},"excerpt":{"rendered":"\u6d59\u5927\u7fc1\u51ef\u8001\u5e08Java\u8bfe\u5802\u5b66\u4e60\u8bb0\u5f55\uff08\u7b2c\u4e09\u5468\uff09\u7b2c\u4e09\u5468\u5b66\u4e60\u7b14\u8bb0\u5bfc\u8bed\uff1aif\u8bed\u53e5\u53ef\u4ee5\u5224\u65ad\u6761\u4ef6\u662f\u5426\u6ee1\u8db3\uff0c\u6ee1\u8db3\u65f6\u624d\u505a\u76f8\u5e94\u7684\u52a8\u4f5c\uff0c\u800c\u5faa\u73af\u8bed...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4901"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=4901"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/4901\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=4901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=4901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=4901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} import java.util.Scanner; public class Hello { public static void main(String[] args) { \/\/ \u521d\u59cb\u5316 Scanner in = new Scanner(System.in); int balance =0;\/\/\u6700\u5f00\u59cb\u7684\u4f59\u989d\u4e3a0 \/\/ \u8bfb\u5165\u6295\u5e01\u91d1\u989d while(true) { System.out.print(\"\u8bf7\u6295\u5e01\uff1a\"); int amount=in.nextInt(); balance = balance+amount;\/\/\u6bcf\u6b21\u94b1\u6295\u8fdb\u6765 if(balance>=10) { \/\/ \u6253\u5370\u8f66\u7968 System.out.println(\"*************\"); System.out.println(\"*Java\u57ce\u9645\u94c1\u8def\u4e13\u7ebf*\"); System.out.println(\"* \u65e0\u6307\u5b9a\u5ea7\u4f4d\u7968 *\"); System.out.println(\"* \u7968\u4ef7\uff1a10\u5143 *\"); System.out.println(\"****************\"); \/\/ \u8ba1\u7b97\u5e76\u6253\u5370\u627e\u96f6 System.out.println(\"\u627e\u96f6\uff1a\"+(balance-10)); balance=0;\/\/\u6e05\u96f6 } } } } <\/code><\/pre>\n
\n\u6848\u4f8b\uff1a\u6570\u6570\u5b57<\/span><\/span><\/h4>\n
import java.util.Scanner; public class Main{ public static void main(String[] args) { \/\/ \u521d\u59cb\u5316 Scanner in = new Scanner(System.in); int number=in.nextInt();\/\/\u8bfb\u8fdb\u6765\u4e00\u4e2a\u6570 int count=0;\/\/\u8ba1\u6570\u5668 while(number>0) { number=number\/10; count=count+1; } System.out.println(\"\u4f4d\u6570\u4e3a\uff1a\"+count); } } <\/code><\/pre>\n
\n
WHILE\u5faa\u73af<\/h3>\n
if(x>0) { x=x\/10; n=n+1; } <\/code><\/pre>\n
while(x>0) { x=x\/10; n=n+1; } <\/code><\/pre>\n
\n\u65b9\u6cd5\uff1a<\/h3>\n
\n import java.util.Scanner; public class Main{ public static void main(String[] args) { \/\/ \u521d\u59cb\u5316 Scanner in = new Scanner(System.in); int number=in.nextInt();\/\/\u8bfb\u8fdb\u6765\u4e00\u4e2a\u6570 int count=0;\/\/\u8ba1\u6570\u5668 while(number>0) { number=number\/10; count=count+1; System.out.println(\"number=\"+number+\";count=\"+count); } System.out.println(\"\u4f4d\u6570\u4e3a\uff1a\"+count); } <\/code><\/pre>\n
\n