C语言字符数组 java封装
1.
int main(void)
{
int a[5] = { 1,3,5,7,9 };
char strl[5] = { 'A','B','C','D','E' };
char str2[5] ="ABCD" ;//不能是ABCDE,最后还有\0
int i = 0;
//for ( i = 0;i < 5;i++)
//{
//printf("%c\n", strl[i]);
//}
printf("%s\n", str2);//数组名就是地址,最后没有\0
str2[1] = 'x';
printf("%s\n", str2);
//str2 = "UBHJ";不能改,前为常量
return 0;
}
2.
(1)
public class girlfriend{ String name; double high; String face; String age; public void setName(String n) { name=n; } public String getName(){ return name; } public void setAge(int a) { if (a>=18&&a<=50){ age= String.valueOf(a); }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("女朋友在学习"); } }
(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); } }