一简单题
1.定义一个类
public class Student{
private String name;
private int age;
private int score;
public student(){
}
public student(String name,int age,int score){
this.name=name;
this.age=age;
this.score=score;
}
public static void main(String args[])
{
Student st1=new Student();
Student st2=new Student("York",23,89)
}
}
1对象st1的name,age,score属性值是什么?
2对象st2的name,age,score属性值是什么?2.定义两个类A,B
public class A{
private int x=10;
public void display(){
System.out.println(x);
}
public class B{
private int x=100;
public void display(){
System.out.println(x);
}
public static void main(String args[]){
A a=new A();
a.display();
}
}
1.程序运行结果是什么?
2.两个类都定义了属性x,这种现象叫什么?二.编程题
1) 10000 = 1 + 9999
10000 = 2 + 9998
10000 = 1 + 2 + 9997
用递归算法求 一共有多少种方法2) 一个文件 和 一个特征字符串
要求在文件中找出 特征字符串 出现的次数
文件要用 二进制流 读入, 特征字符串 是16进制表示的
1.定义一个类
public class Student{
private String name;
private int age;
private int score;
public student(){
}
public student(String name,int age,int score){
this.name=name;
this.age=age;
this.score=score;
}
public static void main(String args[])
{
Student st1=new Student();
Student st2=new Student("York",23,89)
}
}
1对象st1的name,age,score属性值是什么?
2对象st2的name,age,score属性值是什么?2.定义两个类A,B
public class A{
private int x=10;
public void display(){
System.out.println(x);
}
public class B{
private int x=100;
public void display(){
System.out.println(x);
}
public static void main(String args[]){
A a=new A();
a.display();
}
}
1.程序运行结果是什么?
2.两个类都定义了属性x,这种现象叫什么?二.编程题
1) 10000 = 1 + 9999
10000 = 2 + 9998
10000 = 1 + 2 + 9997
用递归算法求 一共有多少种方法2) 一个文件 和 一个特征字符串
要求在文件中找出 特征字符串 出现的次数
文件要用 二进制流 读入, 特征字符串 是16进制表示的
st1.age = 0, st1.name = null, st1.score = 0
st2.age = 23, st2.name = York, st2.score = 89
一.2)
结果:10
什么现象?同构?
public class A extends B {
1对象st1的name,age,score属性值是什么? null 0 0
2对象st2的name,age,score属性值是什么? "York" 23 89实例变量是类的每一个对象的特性;
调用构造函数是对每一个类实例进行统一初始化,没有显示的初始值对象就是null,int就是0;不知道你在这个题的疑问是什么?
第2题:1.程序运行结果是什么?
10
估计你把题目的关联记忆错了2.两个类都定义了属性x,这种现象叫什么?
这个不是什么现象,即使是继承,属性都是类的特性,不觉得是什么现象。
如果是方法要么就是重构 要么就是重写第三编程题
嘿嘿
static int COUNTER = 0; // 计算方法总数(结果)
static int EXP_COUNTER = 0; // 当前表达式的因子数
static int MINUS = 0; // 当前表达式已经减去的因子的和
static int SUM = 1000; // 题目给出的条件 /**
* 递归计算.
* @param begin
* @param step
*/
public void recursive(int begin, int step) {
if ((begin - step) > step) {
EXP_COUNTER++;
MINUS += step;
System.out.print(step + " + ");
if (EXP_COUNTER < COUNTER + 1) {
this.recursive(SUM - MINUS, step + 1); // 当前表达式未结束,继续增加因子
} else {
System.out.println(begin - step); // 当前表达式结束
COUNTER++; // 计算方法总数(结果)加1
if ((begin - step)>(step*2+1)) { // 判断能否继续算下一个表达式,否则得出计算方法总数(结果)
EXP_COUNTER = 0;
MINUS = 0;
this.recursive(SUM, 1); // 重新计算下一个表达式
} else {
System.out.println("###### " + COUNTER + " ######"); // 得出计算方法总数(结果)
System.exit(0);
}
}
}
return;
} public static void main(String[] args) {
new RecursionTest().recursive(SUM, 1);
}
}1 + 999
1 + 2 + 997
1 + 2 + 3 + 994
1 + 2 + 3 + 4 + 990
1 + 2 + 3 + 4 + 5 + 985
1 + 2 + 3 + 4 + 5 + 6 + 979
1 + 2 + 3 + 4 + 5 + 6 + 7 + 972
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 964
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 955
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 945
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 934
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 922
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 909
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 895
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 880
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 864
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 847
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 829
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 810
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 790
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 769
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 747
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 724
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 700
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 675
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 649
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 622
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 594
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 565
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 535
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 504
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 472
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 439
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 405
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 370
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 334
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 297
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 259
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 220
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 180
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 139
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 97
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 54
###### 43 ######
package javatemp1;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class SumDemo {
static int COUNTS = 0; //计算方法总数
static int STEP = 1; //当前表达式的因子个数
static int SUM = 0; //当前表达式的和
static int NUM = 10000; //相加的数 /**
* 递归计算
* @param x
*/ public void sumDemo(int x) {
int i;
for(i = 1; i <= x; i++)
{
//计算表达式
SUM = 0;
while (STEP <= i)
{
System.out.print(STEP + " + ");
SUM += STEP;
STEP++;
}
//显示出表达式中最后一个因子
System.out.print(NUM-SUM);
System.out.println();
STEP = 1;
COUNTS++;
if((NUM-(SUM+i+1)) < (i+1)) break; //判断是否是最后一个表达式
}
System.out.println(COUNTS); }
public static void main(String[] args) {
new SumDemo().sumDemo(NUM);
}}