this.name=name;
this.score=score;
}
public float getRecord(int ID){
if(ID==this.ID)
return this.score;
else
return -1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s=new Student();
s.SetRecord(0,“alex”,100);
float Sco=s.getRecord(0);
System.out.print(Sco);
}
}
3.给出上题中设计类的构造函数,要求初始化一条记录(学号、姓名、成绩)。
public class Student {
- @param args
*/
private int ID;
private String name;
private float score;
Student(int ID,String name,float score){
this.ID=0;
this.name=“666”;. this.score=65;
}
public void SetRecord(int ID,String name,float score){
this.ID=ID;
this.name=name;
this.score=score;
}
public float getRecord(int ID){
if(ID==this.ID)
return this.score;
else
return -1;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s=new Student(0,“sdfs”,12);
//s.SetRecord(0,“alex”,100);
float Sco=s.getRecord(0);
System.out.print(Sco);
}
}
- 编写程序,测试字符串“你好,欢迎来到Java世界”的长度,将字符串的长度转换成字符串进行输出,并对其中的“Java”四个字母进行截取,输出截取字母以及它在字符串中的位置。
public class StringTest {
/**
- @param args
*/
public static void main(String