1.在测试方法中,调用method方法,代码如下,编译正确,试说出method方法的返回类型和参数类型
调用语句为:System.out.println(method(method("john",true),false));
参数类型 : String,boolean
返回值类型 : String
2.定义一个method方法,功能为判断一个字符数组中是否包含某字符
参数: char[],char c
返回值: boolean 或 int(角标)
public boolean method(char[] arrs,char c){
boolean flag=false;
for(int i=0;i<arrs.length;i++){
if(arrs[i]==c){
flag=true;
break;
}
}
return flag;
}
3.要求如下
MyDate
package com.atguigu.home;
public class MyDate {
int year;
int month;
int day;
public boolean isLeapYear(){
if((year%4==0&&year%100!=0)||year%400==0){
return true;
}
return false;
}
public void set(int y,int m,int d){
year =y;
month=m;
day=d;
}
public void plus(int year,int month,int day){
this.year += year;
this.month += month;
this.day += day;
}
}
Home
package com.atguigu.home;
public class Home1 {
/*案例:
声明一个日期类MyDate,包含属性:年、月、日,并在MyDate类中声明几个方法:
1、boolean isLeapYear():判断当前日期的是闰年吗?
2、void set(int y, int m, int d):修改年,月,日为新日期
3、void puls(int years, int months, int days):加上years年,months月,days天后的日期
并在测试类Test04的main方法中创建对象,并调用测试
*/
public static void main(String[] args) {
MyDate myDate = new MyDate();
/* myDate.year=2020;
myDate.month=3;
myDate.day=5;*/
myDate.set(2020,3,5);
boolean leapYear = myDate.isLeapYear();
System.out.println(leapYear);
myDate.set(1,2,3);
myDate.plus(2,4,5);
System.out.println(myDate.year+"-"+myDate.month+"-"+myDate.day);
}
}