java 编程基础题

时间:2016-04-12 05:42:45
【文件属性】:

文件名称: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=10000 && s1<100000) :"); String s2 = new StringBuffer(s1).reverse().toString(); if(s1.equals(s2)){ JOptionPane.showMessageDialog(null,"yes"); }else{ JOptionPane.showMessageDialog(null,"no"); } } } 题目:打印出杨辉三角形(要求打印出10行 import java.util.Scanner; public class YHSanJiao { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a data:"); int n = input.nextInt(); int[][] a = new int[n][n]; for(int i = 0; iuserAnswer.length()){ if(checkString(correctAnswer,userAnswer)) return 2; else return 0; } else return 0; } public static boolean checkString (String correctAnswer,String userAnswer ){ boolean m = true; for(int i = 0; i < userAnswer.length(); ++i){ if(correctAnswer.indexOf(userAnswer.charAt(i))==-1){ m= false; break; } } return m ; } }


网友评论