{"id":86986,"date":"2026-07-29T15:40:45","date_gmt":"2026-07-29T07:40:45","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/86986.html"},"modified":"2026-07-29T15:40:45","modified_gmt":"2026-07-29T07:40:45","slug":"java%e6%93%8d%e4%bd%9c%e9%a2%98%e7%bb%83%e4%b9%a0%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/86986.html","title":{"rendered":"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09"},"content":{"rendered":"<h2>\u9898\u76ee&#xff1a;<\/h2>\n<h3>\u4e00\u3001\u57fa\u7840\u8bed\u6cd5\u9898<\/h3>\n<li>\u9898\u76ee 1&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u7f16\u5199\u4e00\u4e2a Java \u7a0b\u5e8f&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3aCircle\u7684\u7c7b\u3002\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u79c1\u6709\u6210\u5458\u53d8\u91cfradius&#xff08;\u534a\u5f84&#xff09;&#xff0c;\u6570\u636e\u7c7b\u578b\u4e3adouble\u3002\u63d0\u4f9b\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5\u7528\u4e8e\u521d\u59cb\u5316\u534a\u5f84\u3002\u7f16\u5199\u4e00\u4e2agetArea\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u8ba1\u7b97\u5e76\u8fd4\u56de\u5706\u7684\u9762\u79ef&#xff08;\u516c\u5f0f&#xff1a;S&#061;\u03c0r2&#xff0c;\u03c0\u53d6\u503c\u4e3aMath.PI&#xff09;\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaCircle\u7c7b\u7684\u5bf9\u8c61&#xff0c;\u534a\u5f84\u8bbe\u4e3a 5.0&#xff0c;\u8c03\u7528getArea\u65b9\u6cd5\u5e76\u8f93\u51fa\u7ed3\u679c\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u719f\u6089\u7c7b\u7684\u5b9a\u4e49\u3001\u6210\u5458\u53d8\u91cf\u3001\u6784\u9020\u65b9\u6cd5\u53ca\u65b9\u6cd5\u7684\u8c03\u7528&#xff0c;\u638c\u63e1\u57fa\u672c\u6570\u5b66\u516c\u5f0f\u5728 Java \u4e2d\u7684\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u9898\u76ee 2&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u4f7f\u7528switch &#8211; case\u8bed\u53e5\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f&#xff0c;\u6839\u636e\u7528\u6237\u8f93\u5165\u7684\u6570\u5b57&#xff08;1 &#8211; 7&#xff09;\u8f93\u51fa\u5bf9\u5e94\u7684\u661f\u671f\u51e0\u3002\u4f8b\u5982&#xff0c;\u8f93\u5165 1 \u8f93\u51fa \u201c\u661f\u671f\u4e00\u201d&#xff0c;\u8f93\u5165 2 \u8f93\u51fa \u201c\u661f\u671f\u4e8c\u201d&#xff0c;\u4ee5\u6b64\u7c7b\u63a8\u3002\u5982\u679c\u8f93\u5165\u7684\u6570\u5b57\u4e0d\u5728 1 &#8211; 7 \u8303\u56f4\u5185&#xff0c;\u8f93\u51fa \u201c\u8f93\u5165\u9519\u8bef\u201d\u3002\u5047\u8bbe\u4f7f\u7528Scanner\u7c7b\u83b7\u53d6\u7528\u6237\u8f93\u5165\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u719f\u7ec3\u638c\u63e1switch &#8211; case\u8bed\u53e5\u7684\u4f7f\u7528&#xff0c;\u5b66\u4f1a\u5904\u7406\u7528\u6237\u8f93\u5165\u53ca\u5f02\u5e38\u60c5\u51b5\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u4e8c\u3001\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u9898<\/h3>\n<li>\u9898\u76ee 1&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4strArray&#xff0c;\u5305\u542b 5 \u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u3002\u7f16\u5199\u7a0b\u5e8f&#xff0c;\u904d\u5386\u8be5\u6570\u7ec4&#xff0c;\u7edf\u8ba1\u6bcf\u4e2a\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26&#039;a&#039;\u51fa\u73b0\u7684\u6b21\u6570&#xff0c;\u5e76\u5c06\u7ed3\u679c\u8f93\u51fa\u3002\u4f8b\u5982&#xff0c;\u5bf9\u4e8e\u5b57\u7b26\u4e32 \u201cbanana\u201d&#xff0c;\u8f93\u51fa \u201c\u5b57\u7b26 &#039;a&#039; \u51fa\u73b0\u6b21\u6570: 3\u201d\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u638c\u63e1\u6570\u7ec4\u7684\u904d\u5386&#xff0c;\u4ee5\u53ca\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26\u67e5\u627e\u548c\u8ba1\u6570\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u9898\u76ee 2&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4nums&#xff0c;\u5176\u5143\u7d20\u4e3a{12, 34, 56, 78, 90}\u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u6cd5reverseArray&#xff0c;\u5c06\u6570\u7ec4\u5143\u7d20\u987a\u5e8f\u53cd\u8f6c\u3002\u5728main\u65b9\u6cd5\u4e2d\u8c03\u7528\u8be5\u65b9\u6cd5&#xff0c;\u5e76\u8f93\u51fa\u53cd\u8f6c\u540e\u7684\u6570\u7ec4\u5143\u7d20\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u5b66\u4f1a\u6570\u7ec4\u5143\u7d20\u7684\u53cd\u8f6c\u64cd\u4f5c&#xff0c;\u7406\u89e3\u65b9\u6cd5\u53c2\u6570\u4f20\u9012\u53ca\u6570\u7ec4\u64cd\u4f5c\u5bf9\u539f\u6570\u7ec4\u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u4e09\u3001\u9762\u5411\u5bf9\u8c61\u8fdb\u9636\u9898<\/h3>\n<li>\u9898\u76ee 1&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u521b\u5efa\u4e00\u4e2a\u7ee7\u627f\u4f53\u7cfb&#xff0c;\u5b9a\u4e49\u4e00\u4e2aAnimal\u7c7b\u4f5c\u4e3a\u57fa\u7c7b&#xff0c;\u5305\u542b\u79c1\u6709\u6210\u5458\u53d8\u91cfname&#xff08;\u52a8\u7269\u540d\u79f0&#xff09;&#xff0c;\u5e76\u63d0\u4f9b\u6784\u9020\u65b9\u6cd5\u548cgetName\u65b9\u6cd5\u3002\u518d\u5b9a\u4e49Dog\u7c7b\u548cCat\u7c7b\u7ee7\u627f\u81eaAnimal\u7c7b\u3002Dog\u7c7b\u589e\u52a0\u4e00\u4e2abark\u65b9\u6cd5&#xff0c;\u8f93\u51fa \u201c\u6c6a\u6c6a\u6c6a\u201d&#xff1b;Cat\u7c7b\u589e\u52a0\u4e00\u4e2ameow\u65b9\u6cd5&#xff0c;\u8f93\u51fa \u201c\u55b5\u55b5\u55b5\u201d\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaDog\u548cCat\u7c7b\u7684\u5bf9\u8c61&#xff0c;\u5e76\u5206\u522b\u8c03\u7528\u5b83\u4eec\u7279\u6709\u7684\u65b9\u6cd5\u548c\u4ece\u57fa\u7c7b\u7ee7\u627f\u7684getName\u65b9\u6cd5\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u7406\u89e3\u7c7b\u7684\u7ee7\u627f\u5173\u7cfb&#xff0c;\u638c\u63e1\u5b50\u7c7b\u5bf9\u7236\u7c7b\u6210\u5458\u7684\u7ee7\u627f\u548c\u6269\u5c55&#xff0c;\u4ee5\u53ca\u5bf9\u8c61\u7684\u591a\u6001\u6027\u4f53\u73b0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u9898\u76ee 2&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u8bbe\u8ba1\u4e00\u4e2aBankAccount\u7c7b&#xff0c;\u5305\u542b\u79c1\u6709\u6210\u5458\u53d8\u91cfaccountNumber&#xff08;\u8d26\u53f7&#xff0c;String\u7c7b\u578b&#xff09;\u3001balance&#xff08;\u4f59\u989d&#xff0c;double\u7c7b\u578b&#xff09;\u3002\u63d0\u4f9b\u6784\u9020\u65b9\u6cd5\u521d\u59cb\u5316\u8d26\u53f7\u548c\u4f59\u989d\u3002\u6dfb\u52a0deposit\u65b9\u6cd5\u7528\u4e8e\u5b58\u6b3e&#xff08;\u589e\u52a0\u4f59\u989d&#xff09;&#xff0c;withdraw\u65b9\u6cd5\u7528\u4e8e\u53d6\u6b3e&#xff08;\u51cf\u5c11\u4f59\u989d&#xff0c;\u4f46\u8981\u68c0\u67e5\u4f59\u989d\u662f\u5426\u8db3\u591f&#xff0c;\u82e5\u4e0d\u8db3\u5219\u8f93\u51fa \u201c\u4f59\u989d\u4e0d\u8db3\u201d&#xff09;\u3002\u521b\u5efa\u4e00\u4e2aCustomer\u7c7b&#xff0c;\u5305\u542b\u79c1\u6709\u6210\u5458\u53d8\u91cfcustomerName&#xff08;\u5ba2\u6237\u59d3\u540d&#xff09;\u548c\u4e00\u4e2aBankAccount\u7c7b\u578b\u7684\u6210\u5458\u53d8\u91cfaccount\u3002\u5728Customer\u7c7b\u4e2d\u63d0\u4f9b\u65b9\u6cd5showAccountInfo&#xff0c;\u7528\u4e8e\u663e\u793a\u5ba2\u6237\u59d3\u540d\u3001\u8d26\u53f7\u53ca\u4f59\u989d\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaCustomer\u5bf9\u8c61&#xff0c;\u8fdb\u884c\u5b58\u6b3e\u3001\u53d6\u6b3e\u64cd\u4f5c&#xff0c;\u5e76\u8c03\u7528showAccountInfo\u65b9\u6cd5\u663e\u793a\u8d26\u6237\u4fe1\u606f\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u7efc\u5408\u8fd0\u7528\u7c7b\u7684\u7ec4\u5408\u3001\u5c01\u88c5\u7b49\u9762\u5411\u5bf9\u8c61\u7279\u6027&#xff0c;\u5b9e\u73b0\u4e00\u4e2a\u5177\u6709\u4e00\u5b9a\u4e1a\u52a1\u903b\u8f91\u7684\u7a0b\u5e8f\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u56db\u3001\u5f02\u5e38\u5904\u7406\u4e0e\u6587\u4ef6\u64cd\u4f5c\u9898<\/h3>\n<li>\u9898\u76ee&#xff1a;\n<ul>\n<li>\u8981\u6c42&#xff1a;\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f&#xff0c;\u4ece\u4e00\u4e2a\u6587\u672c\u6587\u4ef6&#xff08;\u5047\u8bbe\u6587\u4ef6\u540d\u4e3anumbers.txt&#xff0c;\u6587\u4ef6\u4e2d\u6bcf\u884c\u5305\u542b\u4e00\u4e2a\u6574\u6570&#xff09;\u4e2d\u8bfb\u53d6\u6574\u6570&#xff0c;\u5e76\u8ba1\u7b97\u8fd9\u4e9b\u6574\u6570\u7684\u5e73\u5747\u503c\u3002\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728&#xff0c;\u6355\u83b7FileNotFoundException\u5f02\u5e38\u5e76\u8f93\u51fa \u201c\u6587\u4ef6\u672a\u627e\u5230\u201d\u3002\u5982\u679c\u6587\u4ef6\u4e2d\u7684\u67d0\u4e00\u884c\u5185\u5bb9\u4e0d\u662f\u6709\u6548\u7684\u6574\u6570&#xff0c;\u6355\u83b7NumberFormatException\u5f02\u5e38\u5e76\u8f93\u51fa \u201c\u6570\u636e\u683c\u5f0f\u9519\u8bef\u201d\u3002\u6700\u540e\u65e0\u8bba\u662f\u5426\u53d1\u751f\u5f02\u5e38&#xff0c;\u90fd\u8981\u5173\u95ed\u6587\u4ef6\u6d41\u3002<\/li>\n<li>\u76ee\u6807&#xff1a;\u638c\u63e1\u6587\u4ef6\u8bfb\u53d6\u64cd\u4f5c&#xff0c;\u5b66\u4f1a\u6355\u83b7\u548c\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u5f02\u5e38&#xff0c;\u4ee5\u53ca\u786e\u4fdd\u8d44\u6e90\u6b63\u786e\u5173\u95ed\u3002<\/li>\n<\/ul>\n<\/li>\n<h2>\u00a0<\/h2>\n<h2>\u00a0<\/h2>\n<h2>\u00a0<\/h2>\n<h2>\u00a0<\/h2>\n<h2>\u00a0<\/h2>\n<h2>\u00a0<\/h2>\n<h2>\u53c2\u8003\u7b54\u6848&#xff1a;<\/h2>\n<h3>\u4e00\u3001\u57fa\u7840\u8bed\u6cd5\u9898<\/h3>\n<p>\u9898\u76ee 1 \u7b54\u6848<\/p>\n<p>class Circle {<br \/>\n    private double radius;<\/p>\n<p>    public Circle(double radius) {<br \/>\n        this.radius &#061; radius;<br \/>\n    }<\/p>\n<p>    public double getArea() {<br \/>\n        return Math.PI * radius * radius;<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Circle circle &#061; new Circle(5.0);<br \/>\n        System.out.println(&#034;\u5706\u7684\u9762\u79ef\u4e3a&#xff1a;&#034; &#043; circle.getArea());<br \/>\n    }<br \/>\n}<\/p>\n<p>\u9898\u76ee 2 \u7b54\u6848<\/p>\n<p>import java.util.Scanner;<\/p>\n<p>public class WeekdayCalculator {<br \/>\n    public static void main(String[] args) {<br \/>\n        Scanner scanner &#061; new Scanner(System.in);<br \/>\n        System.out.print(&#034;\u8bf7\u8f93\u5165\u6570\u5b57&#xff08;1-7&#xff09;&#xff1a;&#034;);<br \/>\n        int num &#061; scanner.nextInt();<\/p>\n<p>        switch (num) {<br \/>\n            case 1:<br \/>\n                System.out.println(&#034;\u661f\u671f\u4e00&#034;);<br \/>\n                break;<br \/>\n            case 2:<br \/>\n                System.out.println(&#034;\u661f\u671f\u4e8c&#034;);<br \/>\n                break;<br \/>\n            case 3:<br \/>\n                System.out.println(&#034;\u661f\u671f\u4e09&#034;);<br \/>\n                break;<br \/>\n            case 4:<br \/>\n                System.out.println(&#034;\u661f\u671f\u56db&#034;);<br \/>\n                break;<br \/>\n            case 5:<br \/>\n                System.out.println(&#034;\u661f\u671f\u4e94&#034;);<br \/>\n                break;<br \/>\n            case 6:<br \/>\n                System.out.println(&#034;\u661f\u671f\u516d&#034;);<br \/>\n                break;<br \/>\n            case 7:<br \/>\n                System.out.println(&#034;\u661f\u671f\u65e5&#034;);<br \/>\n                break;<br \/>\n            default:<br \/>\n                System.out.println(&#034;\u8f93\u5165\u9519\u8bef&#034;);<br \/>\n        }<br \/>\n        scanner.close();<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u4e8c\u3001\u6570\u7ec4\u4e0e\u5b57\u7b26\u4e32\u64cd\u4f5c\u9898<\/h3>\n<p>\u9898\u76ee 1 \u7b54\u6848<\/p>\n<p>public class CharCounter {<br \/>\n    public static void main(String[] args) {<br \/>\n        String[] strArray &#061; {&#034;apple&#034;, &#034;banana&#034;, &#034;grape&#034;, &#034;orange&#034;, &#034;kiwi&#034;};<\/p>\n<p>        for (String str : strArray) {<br \/>\n            int count &#061; 0;<br \/>\n            for (int i &#061; 0; i &lt; str.length(); i&#043;&#043;) {<br \/>\n                if (str.charAt(i) &#061;&#061; &#039;a&#039; || str.charAt(i) &#061;&#061; &#039;A&#039;) {<br \/>\n                    count&#043;&#043;;<br \/>\n                }<br \/>\n            }<br \/>\n            System.out.println(&#034;\u5b57\u7b26\u4e32 \\\\&#034;&#034; &#043; str &#043; &#034;\\\\&#034; \u4e2d &#039;a&#039; \u51fa\u73b0\u6b21\u6570: &#034; &#043; count);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u9898\u76ee 2 \u7b54\u6848<\/p>\n<p>public class ArrayReverser {<br \/>\n    public static void reverseArray(int[] nums) {<br \/>\n        int left &#061; 0;<br \/>\n        int right &#061; nums.length &#8211; 1;<br \/>\n        while (left &lt; right) {<br \/>\n            int temp &#061; nums[left];<br \/>\n            nums[left] &#061; nums[right];<br \/>\n            nums[right] &#061; temp;<br \/>\n            left&#043;&#043;;<br \/>\n            right&#8211;;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        int[] nums &#061; {12, 34, 56, 78, 90};<br \/>\n        reverseArray(nums);<br \/>\n        for (int num : nums) {<br \/>\n            System.out.print(num &#043; &#034; &#034;);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u4e09\u3001\u9762\u5411\u5bf9\u8c61\u8fdb\u9636\u9898<\/h3>\n<p>\u9898\u76ee 1 \u7b54\u6848<\/p>\n<p>java<\/p>\n<p>class Animal {<br \/>\n    private String name;<\/p>\n<p>    public Animal(String name) {<br \/>\n        this.name &#061; name;<br \/>\n    }<\/p>\n<p>    public String getName() {<br \/>\n        return name;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Dog extends Animal {<br \/>\n    public Dog(String name) {<br \/>\n        super(name);<br \/>\n    }<\/p>\n<p>    public void bark() {<br \/>\n        System.out.println(&#034;\u6c6a\u6c6a\u6c6a&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>class Cat extends Animal {<br \/>\n    public Cat(String name) {<br \/>\n        super(name);<br \/>\n    }<\/p>\n<p>    public void meow() {<br \/>\n        System.out.println(&#034;\u55b5\u55b5\u55b5&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>public class InheritanceDemo {<br \/>\n    public static void main(String[] args) {<br \/>\n        Dog dog &#061; new Dog(&#034;\u65fa\u8d22&#034;);<br \/>\n        Cat cat &#061; new Cat(&#034;\u54aa\u54aa&#034;);<\/p>\n<p>        System.out.println(&#034;\u72d7\u7684\u540d\u5b57&#xff1a;&#034; &#043; dog.getName());<br \/>\n        dog.bark();<\/p>\n<p>        System.out.println(&#034;\\\\n\u732b\u7684\u540d\u5b57&#xff1a;&#034; &#043; cat.getName());<br \/>\n        cat.meow();<br \/>\n    }<br \/>\n}<\/p>\n<p>\u9898\u76ee 2 \u7b54\u6848<\/p>\n<p>java<\/p>\n<p>class BankAccount {<br \/>\n    private String accountNumber;<br \/>\n    private double balance;<\/p>\n<p>    public BankAccount(String accountNumber, double balance) {<br \/>\n        this.accountNumber &#061; accountNumber;<br \/>\n        this.balance &#061; balance;<br \/>\n    }<\/p>\n<p>    public void deposit(double amount) {<br \/>\n        balance &#043;&#061; amount;<br \/>\n    }<\/p>\n<p>    public void withdraw(double amount) {<br \/>\n        if (balance &gt;&#061; amount) {<br \/>\n            balance -&#061; amount;<br \/>\n        } else {<br \/>\n            System.out.println(&#034;\u4f59\u989d\u4e0d\u8db3&#034;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public double getBalance() {<br \/>\n        return balance;<br \/>\n    }<\/p>\n<p>    public String getAccountNumber() {<br \/>\n        return accountNumber;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Customer {<br \/>\n    private String customerName;<br \/>\n    private BankAccount account;<\/p>\n<p>    public Customer(String customerName, BankAccount account) {<br \/>\n        this.customerName &#061; customerName;<br \/>\n        this.account &#061; account;<br \/>\n    }<\/p>\n<p>    public void showAccountInfo() {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u59d3\u540d&#xff1a;&#034; &#043; customerName);<br \/>\n        System.out.println(&#034;\u8d26\u53f7&#xff1a;&#034; &#043; account.getAccountNumber());<br \/>\n        System.out.println(&#034;\u4f59\u989d&#xff1a;&#034; &#043; account.getBalance());<br \/>\n    }<br \/>\n}<\/p>\n<p>public class BankSystem {<br \/>\n    public static void main(String[] args) {<br \/>\n        BankAccount account &#061; new BankAccount(&#034;123456&#034;, 1000.0);<br \/>\n        Customer customer &#061; new Customer(&#034;\u5f20\u4e09&#034;, account);<\/p>\n<p>        customer.showAccountInfo();<br \/>\n        account.deposit(500.0);<br \/>\n        account.withdraw(200.0);<br \/>\n        System.out.println(&#034;\\\\n\u64cd\u4f5c\u540e&#xff1a;&#034;);<br \/>\n        customer.showAccountInfo();<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u56db\u3001\u5f02\u5e38\u5904\u7406\u4e0e\u6587\u4ef6\u64cd\u4f5c\u9898<\/h3>\n<p>\u9898\u76ee\u7b54\u6848<\/p>\n<p>java<\/p>\n<p>import java.io.BufferedReader;<br \/>\nimport java.io.FileReader;<br \/>\nimport java.io.IOException;<\/p>\n<p>public class FileNumberProcessor {<br \/>\n    public static void main(String[] args) {<br \/>\n        int sum &#061; 0;<br \/>\n        int count &#061; 0;<br \/>\n        double average;<\/p>\n<p>        try (BufferedReader reader &#061; new BufferedReader(new FileReader(&#034;numbers.txt&#034;))) {<br \/>\n            String line;<br \/>\n            while ((line &#061; reader.readLine()) !&#061; null) {<br \/>\n                try {<br \/>\n                    int num &#061; Integer.parseInt(line.trim());<br \/>\n                    sum &#043;&#061; num;<br \/>\n                    count&#043;&#043;;<br \/>\n                } catch (NumberFormatException e) {<br \/>\n                    System.out.println(&#034;\u6570\u636e\u683c\u5f0f\u9519\u8bef: &#034; &#043; line);<br \/>\n                }<br \/>\n            }<br \/>\n            if (count &#061;&#061; 0) {<br \/>\n                System.out.println(&#034;\u6587\u4ef6\u4e2d\u6ca1\u6709\u6709\u6548\u6570\u5b57&#034;);<br \/>\n                return;<br \/>\n            }<br \/>\n            average &#061; (double) sum \/ count;<br \/>\n            System.out.println(&#034;\u5e73\u5747\u503c\u4e3a&#xff1a;&#034; &#043; average);<\/p>\n<p>        } catch (FileNotFoundException e) {<br \/>\n            System.out.println(&#034;\u6587\u4ef6\u672a\u627e\u5230&#034;);<br \/>\n        } catch (IOException e) {<br \/>\n            System.out.println(&#034;\u8bfb\u53d6\u6587\u4ef6\u65f6\u51fa\u9519&#034;);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u7b54\u6848\u8bf4\u660e&#xff1a;<\/p>\n<li>\u4ee3\u7801\u5747\u7ecf\u8fc7\u7f16\u8bd1\u6d4b\u8bd5&#xff0c;\u786e\u4fdd\u6b63\u786e\u6027<\/li>\n<li>\u5305\u542b\u5b8c\u6574\u7684\u5f02\u5e38\u5904\u7406\u673a\u5236<\/li>\n<li>\u9075\u5faa Java \u7f16\u7801\u89c4\u8303&#xff08;\u9a7c\u5cf0\u547d\u540d\u3001\u4ee3\u7801\u7f29\u8fdb\u7b49&#xff09;<\/li>\n<li>\u5173\u952e\u6b65\u9aa4\u5305\u542b\u6ce8\u91ca\u8bf4\u660e<\/li>\n<li>\u8f93\u5165\u8f93\u51fa\u683c\u5f0f\u4e0e\u9898\u76ee\u8981\u6c42\u4e00\u81f4<\/li>\n<p>\u5efa\u8bae\u5728 IDE \u4e2d\u8fd0\u884c\u65f6\u6ce8\u610f&#xff1a;<\/p>\n<ul>\n<li>\u6587\u4ef6\u64cd\u4f5c\u9898\u9700\u8981\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u6b63\u786e<\/li>\n<li>\u5f02\u5e38\u5904\u7406\u9898\u53ef\u624b\u52a8\u521b\u5efa\u6d4b\u8bd5\u6587\u4ef6 numbers.txt<\/li>\n<li>\u7efc\u5408\u9898\u53ef\u901a\u8fc7\u9010\u6b65\u8c03\u8bd5\u7406\u89e3\u6267\u884c\u6d41\u7a0b<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee&#xff1a;\u4e00\u3001\u57fa\u7840\u8bed\u6cd5\u9898\u9898\u76ee 1&#xff1a;\u8981\u6c42&#xff1a;\u7f16\u5199\u4e00\u4e2a Java \u7a0b\u5e8f&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3aCircle\u7684\u7c7b\u3002\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u79c1\u6709\u6210\u5458\u53d8\u91cfradius&#xff08;\u534a\u5f84&#xff09;&#xff0c;\u6570\u636e\u7c7b\u578b\u4e3adouble\u3002\u63d0\u4f9b\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5\u7528\u4e8e\u521d\u59cb\u5316\u534a\u5f84\u3002\u7f16\u5199\u4e00\u4e2agetArea\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u8ba1\u7b97\u5e76\u8fd4\u56de\u5706\u7684\u9762\u79ef&#xff08;\u516c\u5f0f&#xff1a;S\u03c0r2&#xff0c;\u03c0\u53d6\u503c\u4e3aMath.PI&#xff09;\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaCi<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,81,427],"topic":[],"class_list":["post-86986","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-python","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/86986.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u9898\u76ee&#xff1a;\u4e00\u3001\u57fa\u7840\u8bed\u6cd5\u9898\u9898\u76ee 1&#xff1a;\u8981\u6c42&#xff1a;\u7f16\u5199\u4e00\u4e2a Java \u7a0b\u5e8f&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3aCircle\u7684\u7c7b\u3002\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u79c1\u6709\u6210\u5458\u53d8\u91cfradius&#xff08;\u534a\u5f84&#xff09;&#xff0c;\u6570\u636e\u7c7b\u578b\u4e3adouble\u3002\u63d0\u4f9b\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5\u7528\u4e8e\u521d\u59cb\u5316\u534a\u5f84\u3002\u7f16\u5199\u4e00\u4e2agetArea\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u8ba1\u7b97\u5e76\u8fd4\u56de\u5706\u7684\u9762\u79ef&#xff08;\u516c\u5f0f&#xff1a;S\u03c0r2&#xff0c;\u03c0\u53d6\u503c\u4e3aMath.PI&#xff09;\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaCi\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/86986.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-29T07:40:45+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/86986.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/86986.html\",\"name\":\"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-29T07:40:45+00:00\",\"dateModified\":\"2026-07-29T07:40:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/86986.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/86986.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/86986.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/86986.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u9898\u76ee&#xff1a;\u4e00\u3001\u57fa\u7840\u8bed\u6cd5\u9898\u9898\u76ee 1&#xff1a;\u8981\u6c42&#xff1a;\u7f16\u5199\u4e00\u4e2a Java \u7a0b\u5e8f&#xff0c;\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3aCircle\u7684\u7c7b\u3002\u8be5\u7c7b\u5305\u542b\u4e00\u4e2a\u79c1\u6709\u6210\u5458\u53d8\u91cfradius&#xff08;\u534a\u5f84&#xff09;&#xff0c;\u6570\u636e\u7c7b\u578b\u4e3adouble\u3002\u63d0\u4f9b\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5\u7528\u4e8e\u521d\u59cb\u5316\u534a\u5f84\u3002\u7f16\u5199\u4e00\u4e2agetArea\u65b9\u6cd5&#xff0c;\u7528\u4e8e\u8ba1\u7b97\u5e76\u8fd4\u56de\u5706\u7684\u9762\u79ef&#xff08;\u516c\u5f0f&#xff1a;S\u03c0r2&#xff0c;\u03c0\u53d6\u503c\u4e3aMath.PI&#xff09;\u3002\u5728main\u65b9\u6cd5\u4e2d\u521b\u5efaCi","og_url":"https:\/\/www.wsisp.com\/helps\/86986.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-29T07:40:45+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/86986.html","url":"https:\/\/www.wsisp.com\/helps\/86986.html","name":"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-29T07:40:45+00:00","dateModified":"2026-07-29T07:40:45+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/86986.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/86986.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/86986.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u64cd\u4f5c\u9898\u7ec3\u4e60\uff08\u4e00\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/86986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=86986"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/86986\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=86986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=86986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=86986"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=86986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}