从java私塾初级、中级教材中整理出来的,看看基础扎实不扎实。我基础还得加强啊。第一章
1:简述Java 从代码到运行的全过程
 
2:简述虚拟机的工作机制
 
3:简述java的垃圾回收机制
 
4:简述java的安全机制
 
5:简述path、classpath、JAVA_HOME各自的含义和配置方式
 
第二章1:叙述标识符的定义规则,指出下面的标识符中那些是不正确的,并说明理由
   here , _there, this, it, 2to1, _it2:Java中共有那些基本数据类型?分别用什么符号来表示,各自的取值范围是多少?3:复习所有的Java关键字4:指出正确的表达式
    A byte b=128;  
    B char c=65536; 
    C long len=0xfffL;  
    D double dd=0.9239d;5:下面哪几个语句将引起编译错?
    A. float f=4096.0; 
    B. double d=4096.0; 
    C. byte b=4096; 
    D. char c=4096;6:简述Java 中的运算符,以及他们的运算次序。7:创建一个switch 语句,为每一种case 都显示一条消息。并将switch 置入一个for循环里,令其尝试每一种case。在每个case后面都放置一个break,并对其进行测试。然后,删除break,看看会有什么情况出现。8:执行下列代码后的x 和y 的结果分别是什么?
   int x,y,a=2;  
   x=a++;  
   y=++a;  9:下面的程序输出结果是:a=6 b=5
   请将程序补充完整。
     public class A{
       public static void main(String args[]){
         int a=5,b=6;
         a= _a+b_____;
         b=a-b;
         a=__a-b_____;
         System.out.println("a="+a+" b="+b);
       }
     }
 
10:下面哪个语句序列没有错误,能够通过编译?
     A.
      int i=0;
      if (i) {
        System.out.println(“Hi”);
      }
     B.
       boolean b=true;
       boolean b2=true;
       if(b==b2) {
         System.out.println(“So true”);
       }
     C.
       int i=1;
       int j=2;
       if(i==1|| j==2)
         System.out.println(“OK”);
     D.
       int i=1;
       int j=2;
       if (i==1 &| j==2)
         System.out.println(“OK”);11:阅读以下代码行:
      boolean a=false;
      boolean b=true;
      boolean c=(a&&b)&&(!b);
      int result=c==false?1:2;
    这段程序执行完后,c与result的值是:
      A c=false; result=1;
      B c=true; result=2;
      C c=true; result=1;
      D c=false; result=2;12:下列代码哪行会出错?
1) public void modify() {  
2)   int i, j, k;  
3)   i = 100;  
4)   while ( i > 0 ) {  
5)     j = i * 2;  
6)     System.out.println (" The value of j is " + j );  
7)     k = k + 1;  
8)     i--;  
9)   }  
10) }       A 第 4行  
     B 第 6行 
     C 第 7行  
     D 第 8行 
 
13:指出下列程序的运行结果。
    int i = 9;
    switch (i) {
      default:
        System.out.print("default");
      case 0:
        System.out.print("zero"); break;
      case 1:
        System.out.print("one");
      case 2:
        System.out.print("two");
    }     A default
     B defaultzero
     C 编译错
     D 没有任何输出14: 将1 到1000 之间的奇数打印出来。
 
15: 判断一个数能否同时被3和5 整除。
 
16: 输入10个数,找出最大一个数,并打印出来。
 
17: 给出一百分制成绩,要求输出成绩等级’A’,’B’,’C’,’D’,’E’。90 分以上为’A’,80~89 分为’B’,70~79 分为’C’,60~69 分为’D’,60分以下为’E’。
 
18: 输出图案:
*
**
***
****
*
**
***
****
 
19: 使用for 语句打印显示下列数字形式:n=4
      1
    1 2 1
  1 2 3 2 1
1 2 3 4 3 2 1
 
第三章1:写一个MyPoint 完全封装类,其中含有私有的int类型的x 和y 属性,分别用公有的getX 和setX、getY 和setY 方法访问,定义一个toString 方法用来显示这个对象的x、y 的值,如显示(1,2),最后用main 方法测试。2:在MyPoint 类中增加equals()、toString()方法,根据命令行参数个数测试:若不传参数,则显示(0,0);若传一个参数,则打印(此参数值,0);若传两个参数,则打印(第一个参数值,第二个参数值)。3: 有一个序列,首两项为0,1,以后各项值为前两项值之和。写一个方法来实现求这个序列的和4:请编写一个方法实现如下功能:将1至7 的数字转换为星期日到星期六的字符串。5:请编写一个方法实现如下功能:有任意三个整数a,b,c,请输出其中最大的6:请编写一个方法实现如下功能:将任意三个整数a,b,c按从小到大的顺序输出。7:请编写一个方法实现如下功能:用程序找出每位数的立方和等于该数本身值的所有的3 位数。(水仙花数)8:请编写一个方法实现如下功能:计算1 加到n ( n>=2的整数)的总和。9:请编写一个方法实现如下功能:得到一个整数的绝对值。第四章1:创建一个构造方法重载的类,并用另一个类调用2:创建Rodent(啮齿动物):Mouse(老鼠),Gerbil(鼹鼠),Hamster(大颊鼠)等的一个继承分级结构。在基础类中,提供适用于所有Rodent 的方法,并在衍生类中覆盖它们,从而根据不同类型的Rodent 采取不同的行动。创建一个Rodent 数组,在其中填充不同类型的Rodent,然后调用自己的基础类方法,看看会有什么情况发生。3:编写MyPoint的一个子类MyXYZ,表示三维坐标点,重写toString方法用来显示这个对象的x、y、z 的值,如显示(1,2,3),最后用main方法测试4:当你试图编译和执行下面的程序时会发生什么?
class Mystery{
  String s;
  public static void main(String[] args){
    Mystery m=new Mystery();
    m.go();
  }
  voidMystery(){
    s="constructor";
  }
  void go(){
    System.out.println(s);
  }
}
选择下面的正确答案: 
A 编译不通过
B 编译通过但运行时产生异常
C 代码运行但屏幕上看不到任何东西
D 代码运行,屏幕上看到constructor
E 代码运行,屏幕上看到null
 
5:当编译和运行下列程序段时,会发生什么? 
class Person {}
class Woman extends Person {}
class Man extends Person {}
public class Test{
  public static void main(String argv[]){
    Man m=new Man();
    Woman w=(Woman) new Man();
  }
}
A 通过编译和并正常运行。
B 编译时出现例外。
C 编译通过,运行时出现例外。
D 编译不通过
 
6:对于下列代码:
1 class Person {
2   public void printValue(int i, int j) {//... }
3   public void printValue(int i){//... }
4 }
5 public class Teacher extends Person {
6   public void printValue() {//... }
7   public void printValue(int i) {//...}
8   public static void main(String args[]){
9     Person t = new Teacher();
10     t.printValue(10);
11  }
12}
第10 行语句将调用哪行语句?
A line 2
B line 3
C line 6
D line 77:下列代码运行结果是什么? 
public class Bool{
  static boolean b;
  public static void main(String []args){
    int x=0;
    if(b){
      x=1;
    }
    else if(b=false){
      x=2;
    }
    else if(b){
      x=3;
    }
    else{
      x=4;
    }
    System.out.println(“x= ”+x);
  }
}
 
8:在命令行输入java X Y的结果是:
public class X{
  public void main(String []args){
    System.out.println(“Hello ”+args[0]);
  }
}
A. Hello X Y
B. HelloX
C. HelloY
D. 不能编译
E. 运行时有异常
 
9:下列代码编译并运行的结果是: 
public class Test{
  public static void main(String []args){
    class T1 extends java.lang.Thread{}
    class T2 extends T1{}
    class T3 implements java.lang.Runnable{}
    new T1().start();
    new T2().start();
    new Thread(new T3()).start();
    System.out.println(“Executing”);
  }
}
A. 编译失败
B. 程序能运行但永远永不终止
C. 能运行并输出“Executing”
D. 运行时有异常
 
10:代码运行结果是什么?
public class Test{
  public static void main(String []args){
    double num=7.4;
    int a=(int)Math.abs(num+0.5);
    int b=(int)Math.ceil(num+0.5);
    int c=(int)Math.floor(num+0.5);
    int d=(int)Math.round(num+0.5);
    int e=(int)Math.round(num-0.5);
    int f=(int)Math.floor(num-0.5);
    int g=(int)Math.ceil(num-0.5);
    int h=(int)Math.abs(num-0.5);
    System.out.println("a="+a);
    System.out.println("b="+b);
    System.out.println("c="+c);
    System.out.println("d="+d);
    System.out.println("e="+e);
    System.out.println("f="+f);
    System.out.println("g="+g);
    System.out.println("h="+h);
  }
}
  
11:完成此段代码可以分别添加哪两个选项?
1. public class Test{
2.
3.   public static void main(String []args){
4.
5.      System.out.println(“c=”+c);
6.   }
7.}
a)在第2行加上语句static char c;
b) 在第2 行加上语句char c;
c) 在第4 行加上语句static char c;
d) 在第4 行加上语句char c=’f’;
  
12:下列代码运行结果是什么?
public class A{
  puvlic static void main(Stirng []args){
    int m=2;
    int p=1;
    int t=0;
    for(;p<5;p++){
      if(t++>m){
        m=p+t;
      }
    }
    System.out.println(“t equals ”+t);
  }
}
A. 2
B. 4
C. 6
D. 7
 
13:已知如下的命令执行java MyTest a b c  请问哪个是正确的?
A、args[0] = "MyTest a b c"
B、args[0] = "MyTest"
C、args[0] = "a"
D、args[1]= 'b'
 
14:将下面类中的变量和方法改为静态的,使程序能正确编译执行。如果保持用实例变量和方法就必须创建对象,请创建A的对象并通过该对象来引用实例变量和方法。
public classA{
  int a=9;
  public void show(int a){
    System.out.println(a*10);
  }
  public static void main(String args[]){
    a+=a;
    show(a);
  }
}
 
15:设计个Circle类,其属性为圆心点(类型为前面设计的类MyPoint)和半径,并为此类
    编写以下三个方法:
        一是计算圆面积的calArea()方法;
        二是计算周长的calLength();
        三是boolean inCircle(MyPoint mp)方法,功能是测试作为参数的某个点是否在当前对象圆内(圆内,包括圆上返回true;在圆外,返回false)
 

解决方案 »

  1.   

        这个  好多都不会了  
          CRUD 害人不浅啊  框架 - -
      

  2.   

    好多think in java 后面的题
      

  3.   

    [Quote=引用楼主 shoutui 的回复:]
    从java私塾初级、中级教材中整理出来的,看看基础扎实不扎实。我基础还得加强啊。第一章
    1:简述Java 从代码到运行的全过程
      编译, 装载,链接 初始化,连接分为三个阶段 分别是验证,准备和解析,具体干什么不说了,
    其中解析和初始化过程可以调换。
     
    2:简述虚拟机的工作机制
    解释执行class文件,内置GC 
    3:简述java的垃圾回收机制
         GC机制释放不被引用的对像 并处理堆碎片。
    工作方式是,首先检测出垃圾对象 ,然后收回其所占空间。 各种是算法优缺点不说。 按代收集可使用与各种算法,无论如何都可提高最基本的垃圾收集算法的性能。
     
    4:简述java的安全机制
    沙箱机制 、基本沙箱组件
    .类装载器结构.class文件检验器.内置Java虚拟机(及语言)的安全特性.安全管理器及JavaApi
     
      

  4.   

    第二章
    7.public class e {
    public static void main(String args[]){
    int i;
    for(i=0;i<=3;i++){
    switch(i)
    {
    case 0:System.out.println("a"); 
    case 1:System.out.println("b"); 
    case 2:System.out.println("c");
    case 3:System.out.println("d"); 

    }



    }
            
    }}
    a
    b
    c
    d
    b
    c
    d
    c
    d
    d
      

  5.   

    哎,都没用java了,忘了差不多了。而且基础也实在不行啊。好好学习
      

  6.   

    package com.ham.function;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Random;import org.omg.CORBA.FREE_MEM;public class justdoit { private static String oddnum(int nums1, int nums2) {
    String rtnString = "";
    while (nums2 >= nums1) {
    if (nums1 % 2 == 1) {
    rtnString += nums1 + ",";
    }
    nums1 += 1;
    }
    return rtnString;
    } private static boolean canbemod1(int Onum, int Div1) {
    if (Onum % Div1 == 0)
    return true;
    else
    return false;
    } private static boolean canbemod2(int Onum, int Div1, int Div2) {
    return (canbemod1(Onum, Div1) && (canbemod1(Onum, Div2))); } @SuppressWarnings("null")
    private static String maxint() {
    Random rd = new Random();
    int i, rt;
    int[] ns = new int[10];
    for (i = 0; i < 10; i++) {
    ns[i] = rd.nextInt(1000);
    }
    rt = ns[0];
    for (i = 1; i < 10; i++) {
    if (ns[i] > rt)
    rt = ns[i];
    }
    return ns[0] + "," + ns[1] + "," + ns[2] + "," + ns[3] + "," + ns[4]
    + "," + ns[5] + "," + ns[6] + "," + ns[7] + "," + ns[8] + ","
    + ns[9] + "=" + rt;
    } private static String ScoreType(double cj) {
    if (cj >= 90)
    return "A";
    if (cj >= 80)
    return "B";
    if (cj >= 70)
    return "C";
    if (cj >= 60)
    return "D";
    return "E";
    } private static String dsp(int cj) {
    String rt = new String();
    int i = 2;
    rt = cj + "=";
    while (i < cj) {
    while (cj % i == 0) {
    rt += i + " x ";
    cj = (cj / i);
    }
    i++;
    }
    return rt + cj;
    } private static void showPattern() {
    int m, i = 8;
    while (i-- > -6) {
    m = Math.abs(7 - Math.abs(--i));
    while (m > 0) {
    System.out.print("*");
    if (m-- == 1) {
    System.out.println();
    }
    }
    }
    } private static String num2week(int cj) {
    String rt = new String();
    String wk = "日一而三死无流";
    return cj + "=week" + wk.charAt(--cj);
    } private static String maxone(int a, int b, int c) {
    return a + "," + b + "," + c + " max is  "
    + (a > b ? (a > c ? a : c) : (b > c ? b : c));
    } private static String orderby(int a, int b, int c) {
    String rtString = "";
    int maxint;
    maxint = (a > b ? (a > ((c += b) - b) ? a : b) : (b > c ? b : c));
    return a + "," + b + "," + c + " order by is  " + a + "," + b + ","
    + maxint;
    } private static String orderby1(int a, int b, int c) {
    return (a > b ? (a > ((c += b) - b) ? a : b) : 1) + "=" + a + "," + b
    + "," + c;
    } private static void Narcissus() {
    Integer i = 100;
    while (i < 1000) {
    if (i == Math
    .pow(Integer.parseInt(i.toString().substring(0, 1)), 3)
    + Math.pow(Integer.parseInt(i.toString().substring(1, 2)),
    3)
    + Math.pow(Integer.parseInt(i.toString().substring(2, 3)),
    3))
    System.out.print(i + " ");
    i++;
    }
    System.out.println("");
    } private static String Accumulative(int N) {
    Integer rt = 0, i = 1;
    while (i <= N) {
    rt += i++;
    }
    return rt.toString();
    } private static Boolean Contact(String wd) {
    String[] words = new String[10];
    words[0] = "I";
    words[1] = "am";
    words[2] = "a";
    words[3] = "chinese";
    words[4] = "welcome";
    words[5] = "to";
    words[6] = "wenling";
    words[7] = "world";
    words[8] = "wide";
    words[9] = "web";
    int i = 0;
    while (i < words.length) {
    if (words[i++].equals(wd))
    return true;
    }
    return false;
    } private static String randarray() {
    Random rd = new Random();
    int i;
    String rt = new String();
    int[] ns = new int[100];
    for (i = 0; i < 100; i++) {
    ns[i] = rd.nextInt(100);
    rt += ns[i] + ",";
    if ((i + 1) % 10 == 0)
    rt += (char) 10;
    }
    // System.out.println(rt);
    // poporder(ns);
    // rt = "冒泡:";
    // for (i = 0; i < 100; i++) {
    // rt += ns[i] + ",";
    // if ((i + 1) % 10 == 0)
    // rt += (char) 10;
    // }
    System.out.println(rt);
    sort(ns, 0, 99);
    rt = "快速:";
    for (i = 0; i < 100; i++) {
    rt += ns[i] + ",";
    if ((i + 1) % 10 == 0)
    rt += (char) 10;
    }
    return rt;
    } private static void fastorder(int[] data, int i, int j) {
    int tmp, keyint;
    while (i != j) {
    keyint = data[i];
    while ((i < j)) {
    if (data[j] < keyint) {
    tmp = keyint;
    keyint = data[j];
    data[j] = tmp;
    break;
    }
    j--;
    }
    while ((i < j)) {
    if (data[j] > data[i]) {
    tmp = data[i];
    data[i] = data[j];
    data[j] = tmp;
    break;
    }
    i++;
    }
    }
    } private static void poporder(int[] data) {
    int i, j, tmp;
    for (i = 0; i < data.length - 1; i++) {
    for (j = i + 1; j < data.length; j++) {
    if (data[j] < data[i]) {
    tmp = data[i];
    data[i] = data[j];
    data[j] = tmp;
    }
    }
    }
    } public static void sort(int[] data, int low, int high) {
    // 枢纽元,一般以第一个元素为基准进行划分
    int i = low;
    int j = high;
    if (low < high) {
    // 从数组两端交替地向中间扫描
    int pivotKey = data[low];
    // 进行扫描的指针i,j;i从左边开始,j从右边开始
    while (i < j) {
    while (i < j && data[j] - (pivotKey) > 0) {
    j--;
    }// end while
    if (i < j) {
    // 比枢纽元素小的移动到左边
    data[i] = data[j];
    i++;
    }// end if while (i < j && data[i] - (pivotKey) < 0) {
    i++;
    }// end while
    if (i < j) {
    // 比枢纽元素大的移动到右边
    data[j] = data[i];
    j--;
    }// end if
    }// end while
    // 枢纽元素移动到正确位置
    data[i] = pivotKey;
    // 前半个子表递归排序
    sort(data, low, i - 1);
    // 后半个子表递归排序
    sort(data, i + 1, high);
    }// end if
    }// end sort private static String coulationString(String s){
    int i,ichar=0,inum=0,ioth=0;
            for (i=0;i<s.toCharArray().length;i++){
             if ((((byte)s.toCharArray()[i]>=65)&&((byte)s.toCharArray()[i]<91))||
             (((byte)s.toCharArray()[i]>=97)&((byte)s.toCharArray()[i]<122))){
             ichar++;
             }
             else if (((byte)s.toCharArray()[i]>=48)&&((byte)s.toCharArray()[i]<58)) {
    inum++;
    }
             else {
    ioth++;
    }
            }

    return  s+" 字母:"+ichar+" 数字:"+inum+" 其他字符:"+ioth;
    } private static float intarraytotal(int ttlint){
    int i,tmp,fz=1,fm=1;
    float tl=0;
    for (i=0;i<(ttlint);i++){
    tmp=fm;
    fm=fz;
    fz=fz+tmp;
    tl+=(float)(fz)/(float)fm;
    }
    return tl;
    }
    public static void main(String[] args) throws IOException {
    System.out.println(oddnum(1, 1000));
    System.out.println("15:3,5=" + Boolean.toString(canbemod2(15, 3, 5)));
    System.out.println("36:3,5=" + Boolean.toString(canbemod2(36, 3, 5)));
    System.out.println(maxint());
    System.out.println(ScoreType(59.30));
    System.out.println(ScoreType(89.30));
    System.out.println(dsp(24));
    showPattern();
    System.out.println(num2week(1));
    System.out.println(maxone(15, 9, 17));
    System.out.println(orderby1(15, 10, 19));// 有问题 想一行返回值
    Narcissus();
    System.out.println(Accumulative(4));
    System.out.println(3 >>> 6); InputStreamReader reader = new InputStreamReader(System.in);
    BufferedReader input = new BufferedReader(reader);
    System.out.println(Contact(input.readLine())); System.out.println(randarray());
    System.out.println(coulationString("1开1s~1*2a深刻f^f22.ss2ad"));
    System.out.println(intarraytotal(20));//16已经 在上上题实现
    //有一分数序列:2/1,3/2,5/3,8/5,..求出这个数列的前20项之和。 (不使用数学公式,要求用递归)
    }}
    最后 这个不会用递归啊~~
      

  7.   

    sort() 方法网上找的;还没有懂~~   - -!
      

  8.   

    第三章
    1、
    public class MyPoint{
     private int x,y;
     public int getX(){
      return x;
     }
     public int getY(){
      return y;
     }
     public void setX(int a){
       x=a;
     }
     public void sety(int b){
       y=b;
     }
     public String toString(){
      return "("+x+","+y+")";
      //System.out.println("("+x+","+y+")");
     }
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      MyPoint point = new MyPoint();
      point.setX(2);
      point.sety(3);
      point.getX();
      point.getY();
      System.out.println(point);
      System.out.println(point.getX());
      System.out.println(point.getY());
      System.out.println(point.toString());
     }
    }
      

  9.   

    2、
    public class MyPoint{
     private int x,y;
     public MyPoint(){
      x=0;
      y=0;
     }
     public MyPoint(int a){
      x=a;
      y=0;
     }
     public MyPoint(int a,int b){
      x=a;
      y=b;
     }
     public String toString(){
      return "("+x+","+y+")";
     }
     public boolean equals(MyPoint t){
      if (this.x==t.x && this.y == t.y){
       return true;
      }else
      {
       return false;
      }
     }
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      MyPoint point = new MyPoint();
      MyPoint point1 = new MyPoint(2);
      MyPoint point2 = new MyPoint(3);
      System.out.println(point.equals(point));
      System.out.println(point.equals(point));
      System.out.println(point);
      System.out.println(point1);
      System.out.println(point2);
     }
    }
      

  10.   

    第六章 10题import java.util.Iterator;
    import java.util.LinkedList;
    public class test {
     // 定义三个String对象
     public static final String rabbitName = "猫";
     public static final String wolfName = "狗";
     public static final String cabbageName = "鱼";
     // 判断两个对象之间关系是否友好
     public static boolean isFriendly(Goods goods1, Goods goods2) {
      if (goods1 != null) {
       //猫不会和其他两位共存,只能单独
       if (goods1.getGoodsName().trim().equals(rabbitName)) {
        if (goods2 == null) {
         return true;
        } else {
         return false;
        }
        //鱼和狗可以共存
       } else if (goods1.getGoodsName().trim().equals(wolfName)) {
        if (goods2 == null
          || goods2.getGoodsName().trim().equals(cabbageName)) {
         return true;
        } else {
         return false;
        }
         //狗和鱼可以共存
       } else if (goods1.getGoodsName().trim().equals(cabbageName)) {
        if (goods2 == null
          || goods2.getGoodsName().trim().equals(wolfName)) {
         return true;
        } else {
         return false;
        }
        //什么也不是的时候
       } else {
        return false;
       }
      //空无一物的时候是友好的 
      } else {
       return true;
      }
     }
     // test主程序
     public static void main(String[] args) {
      //两个列表一个移之前,一个移之后
      boolean isSuccess = false;
      LinkedList<Goods> beforeCrossing = new LinkedList<Goods>();
      LinkedList<Goods> afterCrossing = new LinkedList<Goods>();
      beforeCrossing.add(new Goods(cabbageName));
      beforeCrossing.add(new Goods(rabbitName));
      beforeCrossing.add(new Goods(wolfName));
      //只要没成功就不停的执行
      while (!isSuccess) {
       //取第一个
       Goods goods1 = beforeCrossing.getFirst();
       System.out.println(goods1.getGoodsName() + " 被取走了");
       beforeCrossing.removeFirst();
       //判断是否已经取完
       if (beforeCrossing.isEmpty()) {
        afterCrossing.addLast(goods1);
        isSuccess = true;
        System.out.println("全部移动完毕!");
       } else {
        //没有取完的话,首先看有谁留下了
        Iterator<Goods> it = beforeCrossing.iterator();
        Goods[] beforeCro = new Goods[2];
        for (int i = 0; it.hasNext(); i++) {
         beforeCro[i] = it.next();
         System.out.println(beforeCro[i].getGoodsName() + " 留了下来");
        }
        //看留下的两位是否关系友好,或者是一位,或者没了
        if (isFriendly(beforeCro[0], beforeCro[1])) {
         //留下的友好,且对岸没有时,成功已过去
         if (afterCrossing.isEmpty()) {
          afterCrossing.addLast(goods1);
          System.out.println(goods1.getGoodsName() + " 被成功的放到了对岸");
         //留下的友好,但是对岸已经有东西了, 
         } else {
          Goods goods2 = afterCrossing.getFirst();
          //对岸的东西和将要移的东西,是否友好,好则移动
          if (isFriendly(goods1, goods2)) {
           afterCrossing.addLast(goods1);
           System.out.println(goods1.getGoodsName()
             + " 被成功的放到了对岸");
          //对岸的东西和将要移动的东西,不友好,将对岸的东西移回去,并加到末尾去,要移动的留下
          } else {
           beforeCrossing.addLast(goods2);
           afterCrossing.removeFirst();
           System.out.println(goods1.getGoodsName() + " 与 "
             + goods2.getGoodsName() + "并不和睦 于是把 "
             + goods2.getGoodsName() + "带了回来 并将 "
             + goods1.getGoodsName() + " 留了下来");
          }
         }
        } else {
         //留下的两位看来并不友好
         beforeCrossing.addLast(goods1);
         System.out.println("很可惜 留下来的两个东西并不和睦 于是 " + goods1.getGoodsName() + " 又被放了回去");
        }
       }
      }
     }
    }
    // 货物类,动物类什么的,反正方法类似,拷贝的程序
    class Goods {
     // 货物名称
     private String goodsName;
     // 默认构造方法
     public Goods(String goodsName) {
      this.goodsName = goodsName;
     }
     // 获得货物名称
     public String getGoodsName() {
      return goodsName;
     }
    }
      

  11.   

    第六章 9题
    public class test{
     public double money(int num){
      if(num <=10){
       return num*0.1;
      }else if(num <= 20){
       return 1+(num-10)*0.075;
      }else if(num <= 40){
       return 1.75+(num-20)*0.05;
      }else if(num <= 60){
       return 2.75+(num-40)*0.03;
      }else if(num <= 100){
       return 3.35+(num-60)*0.015;
      }else {
       return 3.95+(num-100)*0.01;
      }
     }
     public static void main(String[] args) throws IOException{
      System.out.println("请输入当月利润(万元):");
      Scanner sc = new Scanner(System.in);
      System.out.println(new test().money(sc.nextInt()));
     }
    }
      

  12.   

     1:简述Java 从代码到运行的全过程
       分为编译阶段和运行阶段
       编辑代码成java文件>>>编译代码成字节码class文件>>> 类装载:寻找所需要的类,分离本地类和网络类,进行安全检查>>>字节码校验>>>解释成机器码>>>运行
       2:简述虚拟机的工作机制
       通过类装载寻找和装载class文件,
       解释字节码成为指令并执行,提供class文件的运行环境,
       进行运行期间垃圾回收
       提供与硬件交互的平台
       3:简述Java 的垃圾回收机制
       在需要的时候回收,通知了回收不一定就会去执行
       4:简述Java 的安全机制
       代码编译检查
       类装载检查 
       字节码校验
       沙箱保护
       5:简述path、classpath、JAVA_HOME各自的含义和配置方式
       path 操作系统找java工具jdk\bin路径,如:“D:\common\Java\jdk1.6.0_02\bin;”,注意不要忘了后面的分号
       classpath 程序运行时寻找资源类路径,变量值为:.;
       JAVA_HOME  其他需要java程序的jdk路径,如:D:\common\Java\jdk1.6.0_02 
     
    含义:
    PATH: 提供给操作系统寻找到Java 命令工具的路径。通常是配置到JDK 安装路径\bin 
    JAVA_HOME: 提供给其它基于Java 的程序使用,让它们能够找到JDK 的位置。通常配置到JDK 安装路径。注意:这个必须书写正确,全部大写,中间用下划线。 
    CLASSPATH: 提供程序在运行期寻找所需资源的路径,比如:类、文件、图片等等
      

  13.   

    最后一题public class Test {
    public static void main(String[] args) throws Exception {
    Map<String, Object> p = new HashMap<String, Object>();
    p.put("id", 110);
    p.put("name", "demo"); Model m = (Model) getModel(p, Model.class); System.out.println(m.getId());
    System.out.println(m.getName());
    } public static Object getModel(Map p, Class cla) throws Exception { Object obj = cla.newInstance();
    for (Iterator it = p.entrySet().iterator(); it.hasNext();) {
    Entry e = (Entry) it.next(); String fieldName = (String) e.getKey();
    Object fieldValue = e.getValue(); String methodName = "set" + String.valueOf(fieldName.charAt(0)).toUpperCase() + fieldName.substring(1); cla.getMethod(methodName, fieldValue.getClass()).invoke(obj, fieldValue);
    }
    return obj;
    }}
      

  14.   

    第三章
    1、
    public class MyPoint{
     private int x,y;
     public int getX(){
      return x;
     }
     public int getY(){
      return y;
     }
     public void setX(int a){
       x=a;
     }
     public void sety(int b){
       y=b;
     }
     public String toString(){
      return "("+x+","+y+")";
      //System.out.println("("+x+","+y+")");
     }
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      MyPoint point = new MyPoint();
      point.setX(2);
      point.sety(3);
      point.getX();
      point.getY();
      System.out.println(point);
      System.out.println(point.getX());
      System.out.println(point.getY());
      System.out.println(point.toString());
     }
    }
      

  15.   

    第二章,简单,显摆一下。14: 将1 到1000 之间的奇数打印出来。
     public class test{
      public static void main(String args[]) {
        int i=0;
        while(i<500){
          System.out.println("奇数:"+ (i*2+1));
           i++;
        }
      }
    }
    15: 判断一个数能否同时被3和5 整除。
     
    public class test{
     public static void main(String args[]) {
      int x=15;
      if (x%3==0 && x%5==0){
       System.out.println("right");
      }else{
       System.out.println("wrong");
      }
       
     }
    }16: 输入10个数,找出最大一个数,并打印出来。
     
    public class test{
     public static void main(String args[]) {
      int[] a={1,10,3,4,5,6,7,8,9,2};
      int tmp;
      for(int i=1;i<a.length;i++){
       if(a[i-1]>a[i]){
        tmp=a[i-1];
        a[i-1]=a[i];
        a[i]=tmp;
       }
      }
      System.out.println("应该是10:"+a[9]);
     }
    }17: 给出一百分制成绩,要求输出成绩等级’A’,’B’,’C’,’D’,’E’。90 分以上为’A’,80~89 分为’B’,70~79 分为’C’,60~69 分为’D’,60分以下为’E’。
     
    public class test
    {
     public static void main(String args[])
     {
      int myGrade[] ={23,90,50,70,63,80,100};
      for(int i=0;i<myGrade.length;i++){
       switch(myGrade[i]/10){
       case 10:
       case 9: System.out.println("A:"+(myGrade[i]));break;
       case 8: System.out.println("B:"+(myGrade[i]));break;
       case 7: System.out.println("C:"+(myGrade[i]));break;
       case 6: System.out.println("D:"+(myGrade[i]));break;
       default: System.out.println("E:"+(myGrade[i]));break;
       }
      }
     }
    }18: 输出图案:
    *
    **
    ***
    ****
    *
    **
    ***
    ****
     public class test{
     public static void main(String args[]) {
      for(int j=0;j<2;j++){
       String a ="*";
       for(int i=0;i<4;i++){
        System.out.println(a);
        a=a+'*';
        }
       }
      }
    }
    19: 使用for 语句打印显示下列数字形式:n=4
          1
        1 2 1
      1 2 3 2 1
    1 2 3 4 3 2 1
    public class test{
     public static void main(String args[]) {
      int n=4;
      for(int j=0;j<n;j++){
       for(int i=1;i<=j+1;i++){
        System.out.print(i+" ");
        }
       for(int k=j;k>0;k-- ){
        System.out.print(k+" ");
        }
       System.out.println();
       }
     }
    }