标签:
Day1共7题
package com.pcx.day1; /** * 设一个字符数组,对其元音字母进行统计 * a e i o u * @author Administrator * */ public class YuanYin { ????public static void main(String[] args) { ????????char [] chars={‘a‘,‘b‘,‘c‘,‘d‘,‘e‘}; ????????int count=0; ????????for (int i = 0; i < chars.length; i++) { ????????????if (chars[i]==‘a‘||chars[i]==‘e‘||chars[i]==‘i‘||chars[i]==‘o‘||chars[i]==‘u‘) { ????????????????count++; ????????????} ????????} ????????System.out.println("元音字母的个数为:"+count); ????} } ? |
package com.pcx.day1; /** * 打印1000以内的水仙花数 * 153 * @author Administrator * */ public class ShuiXianHua { ????public static boolean isShuiXianHuan(int a){ ????????int ge=a%10; ????????int shi=a/10%10; ????????int bai=a/100; ????????if (Math.pow(ge,3)+Math.pow(shi,3)+Math.pow(bai,3)==a) { ????????????return true; ????????}else { ????????????return false; ????????} ????} ???? ????public static void main(String[] args) { ????????for (int i = 100; i < 1000; i++) { ????????????if (isShuiXianHuan(i)) { ????????????????System.out.println(i+" 是水仙花数"); ????????????} ????????} ????} } |
package com.pcx.day1; ? import java.util.Calendar; ? public class RiQi { ????/** ???? * 接收三个参数分别是年,月,日,然后返加一个Calendar类型的对象 ???? */ ????public static Calendar getCalendar(int year, int month, int day){ ????????Calendar c=Calendar.getInstance(); ????????c.set(year, month, day); ????????return c; ????} ???? ????/** ???? * 打印此日期是一个月的第几天,一年的第几天,一周的第几天,此天是周几,这个月的第一天是周几,是一周的第几天。 ???? * @param c ???? */ ????public static void show(Calendar c ){ ????????System.out.println("这个月的第几天:"+c.get(Calendar.DAY_OF_MONTH)); ????????System.out.println("这个年的第几天:"+c.get(Calendar.DAY_OF_YEAR)); ????????System.out.println("这个周的第几天:"+c.get(Calendar.DAY_OF_WEEK)); ????????System.out.println("这天周几:"+(c.get(Calendar.DAY_OF_WEEK)-1)); ???????? ????????c.set(Calendar.DATE, 1); ????????System.out.println("这个月的第一天是一周的第几天:"+c.get(Calendar.DAY_OF_WEEK)); ????????System.out.println("这天周几:"+(c.get(Calendar.DAY_OF_WEEK)-1)); ????} ???? ????public static void main(String[] args) { ????????show(getCalendar(2015, 6, 28)); ????} } |
package com.pcx.day1; ? public class Person { ????private String name; ????private int age ; ????private boolean gendar;//true 男 false 女 ????public String getName() { ????????return name; ????} ????public void setName(String name) { ????????this.name = name; ????} ????public int getAge() { ????????return age; ????} ????public void setAge(int age) { ????????this.age = age; ????} ????public boolean isGendar() { ????????return gendar; ????} ????public void setGendar(boolean gendar) { ????????this.gendar = gendar; ????} ???? ????public void walk(){ ????????System.out.println(this.name+"在走。。。"); ????} ???? ????public void eat(){ ????????System.out.println(this.name+"在吃。。。"); ????} } ? package com.pcx.day1; ? public class PersonTest { ????public static void main(String[] args) { ????????//Lucy,女,23岁;Jame,男,25岁 ????????Person p1=new Person(); ????????p1.setName("lucy"); ????????p1.setGendar(false); ????????p1.setAge(23); ????????Person p2=new Person(); ????????p2.setName("Jame"); ????????p2.setGendar(true); ????????p2.setAge(25); ????????p1.walk(); ????????p1.eat(); ????????p2.walk(); ????????p2.eat(); ????} } |
package com.pcx.day1; /** * 求1+2!+3!+...+20!的和 * @author Administrator * */ public class Jiechenghe { ????public static int getJieCheng(int a){ ????????if(a==0||a==1){ ????????????return 1; ????????}else { ????????????return a*getJieCheng(a-1); ????????} ????} ????public static void main(String[] args) { ????????int sum=0; ????????for (int i = 1; i <=20; i++) { ????????????sum+=getJieCheng(i); ????????} ????????System.out.println("1+2!+3!+...+20!="+sum); ????} } |
package com.pcx.day1; /** * 一球从100米高度自由落下,每次落地后反跳回原高度的一半; * 再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高? * @author Administrator * */ public class Qiu { ????public static void main(String[] args) { ????????int gao=100,gn=gao/2; ????????int total=0+100; ????????for (int i =2; i <=10; i++) { ????????????total=total+2*gn; ????????????gn=gn/2; ????????} ????????System.out.println("十次一共经过了:"+total+"米"); ????????System.out.println("第十次反弹:"+gn); ????} } |
标签:
原文地址:http://www.cnblogs.com/chengzhipcx/p/4605913.html