1.
(1)
public class girlfriend{ String name; double high; String face; String age; //在方法里面是局部变量,在方法外面是成员变量public void setName(String name) {this.name=name;}public String getName(){return name;}public void setAge(int age) {if (age>=18&&age<=50){this.age= String.valueOf(age);}else{System.out.println("错误");}}public String getAge(){return age;}public void setFace(String c) {face=c;}public String getFace(){return face;}public void sleep(){System.out.println("女朋友在睡觉");}public void study(){System.out.println("女朋友在学习");}/* private int age;public void methon(){int age=18;System.out.println(this.age);//用成员变量必须在age前加this}*/ }
(2)
public class girlfriendTest {public static void main(String[] args) {girlfriend f = new girlfriend();f.setName("fanwenshuo");f.setAge(18);f.setFace("keai");System.out.println(f.getName());System.out.println(f.getAge());System.out.println(f.getFace());System.out.println(f.face);System.out.println(f.name);}/*public static void main(String[] arges){girlfriend f=new girlfriend();f.methon();}*/ }
2.
int main(void)
{
char str[10] = "ABCD";
//printf("%s\n", str);//从第几个开始往后输出
char* p;//*后跟着哪个元素的地址,就等于哪个元素本身
char* p1;
p = str;//p=&str[0]
*p = 'X';//str[0]='X'
//printf("%s\n", p);
//p[2] += 32;//str[2] += 32;p[2] += 32;
printf("%s\n", str);
printf("%s\n", p);
//p1 = "HIJK";不能转换为char
//printf("%s\n", p1);
return 0;
}