文件名称:java 编程基础题
文件大小:102KB
文件格式:DOC
更新时间:2016-04-12 05:42:45
类 素数 回文数 杨辉三角形
写出一个类People,并由该类做基类派生出子类Employee和Teacher。其中People类具有name、age两个保护成员变量,分别为String类型和整型,且具有共有的getAge()成员方法,用于返回age变量的值,并编写一个两个参数的构造函数。Employee类具有保护成员String变量employeeNo,Teacher类有String类型的teano和zc变量,并分别为两个子类编写一个无参的构造函数。若使两个子类正常的编译,请在父类中解决该问题。
public class Employee extends People{
protected String employeeNo ;
//construct method
Employee()
{
}
}
package Exercise1;
public class People {
protected String name ;
protected int age ;
//construct method
People()
{
}
People(String name,int age)
{
this.name = name ;
this.age = age ;
}
//getAge
public int getAge()
{
return this.age ;
}
}
package Exercise1;
public class Teacher extends People{
protected String teano ;
protected String zc ;
//construct method
Teacher()
{
}
}
package Exercise1;
public class MainTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Employee em = new Employee();
em.age = 20;
em.employeeNo = "1234560";
em.name = "Jim" ;
System.out.println("Employee : name :"+em.name+"age:"+em.age+"emplyeeNo:"+em.employeeNo);
Teacher tea = new Teacher();
tea.age = 26;
tea.name = "Tom" ;
tea.teano= "456";
tea.zc = "Go" ;
System.out.println("Teacher : name :"+tea.name+"age:"+tea.age+"teano:"+tea.teano+"zc:"+tea.zc);
}
}
题目:判断101-200之间有多少个素数,并输出所有素数。
public class SuShu {
public static void main(String[] args) {
int m;
int i;
int k=0;
for(m=1;m<=100;m++)
{
for(i=2;i