第一题
package com.hp.zhang; import com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI; public class test1 { public static void main(String[] args) { double c=sum(5,6); System.out.println("和为"+c); } public static double sum(int a,double b) { double sum = a + b; if (a == b) { System.out.println("两个数相等"); } else { System.out.println("两个数不相等"); } return sum; }}
第二题
package com.hp.zhang; import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput; public class test2 { public static void main(String[] args) { //长方形 int chang = 10; int kuan = 5; int c = (chang + kuan) * 2; System.out.println("长方形的周长为" + c); int s = chang * kuan; System.out.println("长方形的面积为" + s); //圆 int r = 5; double zhouchang = 2 * 3.14 * r; System.out.println("圆的周长"+zhouchang+"米"); double mianji = 3.14*r*r; System.out.println("圆的周长"+mianji+"米"); } }
第三题
package com.hp.zhang; public class test3 { public static void main(String[] args) { System.out.println("================================"); int count2=0; int i=100; while(i<1000){ int ge=i%10; int shi=i/10%10; int bai=i/10/10%10; if (ge*ge*ge+shi*shi*shi+bai*bai*bai==i) { System.out.println(i); count2++; } i++; } System.out.println("有水仙花数为:"+count2+"个"); } }
第四题
package com.hp.zhang; public class test4 { public static void main(String[] args) { for (int n =1; n <=11 ; n++) { System.out.println("HellowWord"); } System.out.println(); } }
第五题
package com.hp.zhang; public class test5 { public static void main(String[] args) { int sum=0; for (int i = 2; i <=100 ; i++) { if (i % 2 == 0) { } System.out.println(i); sum+=i; } System.out.println("所有偶数的和为"+sum); }}