码迷,mamicode.com
首页 > 编程语言 > 详细

Java编程题每日一练day1

时间:2015-06-28 18:49:00      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

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);

????}

}

Java编程题每日一练day1

标签:

原文地址:http://www.cnblogs.com/chengzhipcx/p/4605913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!