JAVA 编程思想第一章习题

2018-11-05 08:22:59来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

 

//: ch1.01/IntChar.java
package object; 
import java.util.*;

public class IntChar {
     int x; char y; 
     public IntChar(){
         System.out.println(x);
        System.out.println(y); 
         } 
    public static void main(String[] args) {
         new IntChar(); 
    }
 }

/* output:
test
*///~


 

package Object;
//: ch1.2/HelloWorld.java

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }

}/*
     * output:(55% match) hell. it's:
     *  Wed Nvember 01 13:42 MDT 2018
     */// :~
//: ch1.3/ATypeName.java
package Object;

import java.util.*;

public class ATypeName{
    int x;
    public static void main(String[] args){
        ATypeName a = new ATypeName();
        a.x=4;
        System.out.print(a.x);
    }
    
}
/* class object
*/// :~
//: ch1.4/DataOnly.java
/**study
 * @author feilong
 */
package Object;
import java.util.*;

public class DataOnly{
    public static void main(String[] args){
        DataOnly data = new DataOnly();
    }
}
//: ch1.5/Dataonly.java
/**study
 * @author feilong
 */
package Object;
import java.util.*;

public class Dataonly{
        int x;
        double d;
        boolean b;

    public static void main(String[] args){
        Dataonly data = new Dataonly();
        data.x=47;
        data.d=1.1;
        data.b=false;
        System.out.println("data.x="+data.x);
        System.out.println("data.d="+data.d);
        System.out.println("data.b="+data.b);
    }
}/* output
data.x = 47
data.d = 1.1
data.b = false
*///:~
//: ch1.6/Storage.java
/**@version 1.6
* @author feilong
*/
package Object;
import java.util.*;

public class Storage{
    public int storage(String s){
        return s.length()*2;
    }
    public static void main(String[] args){
        Storage st = new Storage();
        String s  = "helloword";
        int l=st.storage(s);
        System.out.println(l);
    }
}
/* output:
 * storage(s);
 *///:~
//: ch1.7/Incrementable.java
/**@author feilong
*  @version 1.7
*/
package Object;
import java.util.*;

class StaticTest{
    static int i = 47;
}


public class Incrementable{
    
    
    static void increment()
    {
        StaticTest.i++;
    }
    public static void main(String[] args){
        Incrementable sf = new Incrementable();
        sf.increment();
        System.out.println(StaticTest.i);
    }
}/* Output:
StaticTest.i
*///:~
//: ch1.8/ShowStatic.java
/**@author feilong
*  @version 1.8
*/
package object;
import java.util.*;
public class ShowStatic{
    static int i = 7;
    
    public static void main(String[] args){
        ShowStatic ss = new ShowStatic();
        ss.i=9;
        ShowStatic sy = new ShowStatic();
        ShowStatic sz = new ShowStatic();
        System.out.println("ss.i = "+ss.i);
        System.out.println("sy.i = "+sy.i);
        System.out.println("sz.i = "+sz.i);
    }
}/* output:
ss.i = 9
sy.i = 9
sz.i = 9
*///:~

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Java并发(七):双重检验锁定DCL

下一篇:【Java】数组知识回顾