大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 部分Java編程思想答案

部分Java編程思想答案

更新時間:2022-03-24 11:02:31 來源:動力節點 瀏覽1454次

1.創建一個類,它包含一個int域和一個char域,它們都沒有被初始化,將它們的值打印出來,以驗證Java執行了默認初始化。

private static char c;
private static int i;
public static void main(String[] args){
    System.out.println(String.valueOf(c));
    System.out.println(String.valueOf(i));
}

返回值:

0

2.找出含有ATypeName的代碼段,將其改為完整的程序。

public class ATypeName {
    /* Class body goes here */
    private String id;
    private String name;
    public ATypeName() {
    }
    public ATypeName(String id, String name) {
        this.id = id;
        this.name = name;
    }
    @Override
    public String toString() {
        return "ATypeName{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
public class Main{
    public static void main(String[] args){
        ATypeName a = new ATypeName(1,"張三");
        System.out.println(a.toString());
    }
}

返回:ATypeName{id='1', name='張三'}

3.編寫一個程序,讓它含有本章所定義的storage()方法的代碼段,并調用之。

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println(storage("HelloWorld"));
    }
    private static int storage(String s) {
        return s.length() * 2;
    }
}

4.將Incrementtable的代碼改寫成一個完整的可運行程序。

public class StaticTest {
    static int i = 47;
}
public class Incrementtable {
   static void increment(){
       StaticTest.i++;
   }
}
public class HelloWorld {
    public static void main(String[] args){
        System.out.println("before StaticTest.i:" + StaticTest.i);
        Incrementtable.increment();
        System.out.println("after StaticTest.i:" + StaticTest.i);
    }
}

返回:

before StaticTest.i:47

after StaticTest.i:48

5.編寫一個程序,展示無論你創建了某個特定類的多少個對象,這個類中的某個特定的static域只有一個對象。

public class StaticTest {
    static String s = new String("HelloWorld");
}
public class HelloWorld {
    public static void main(String[] args) {
        StaticTest st1 = new StaticTest();
        StaticTest st2 = new StaticTest();
        StaticTest st3 = new StaticTest();
        StaticTest st4 = new StaticTest();
        System.out.println("st1.s == st2.s : "+(st1.s == st2.s));
        System.out.println("st1.s == st3.s : "+(st1.s == st3.s));
        System.out.println("st1.s == st4.s : "+(st1.s == st4.s));
    }
}

返回:

st1.s == st2.s : true

st1.s == st3.s : true

st1.s == st4.s : true

6.編寫一個程序,展示自動包裝功能對所有的基本類型和包裝器類型都起作用。

public class HelloWorld {
    public static void main(String[] args) {
        int i1 = 127;
        Integer ii1 = i1;
        int i2 = ii1;
        int i3 = 128;
        Integer ii2 = i3;
        int i4 = ii2;
    }
}

7.編寫一個程序,打印出從命令行獲取的三個參數。為此,要確定命令行數組中String的下標。

public class HelloWorld {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String s1 = s.next();
        String s2 = s.next();
        String s3 = s.next();
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
}

輸入:

hello

world

!

返回:

hello

world

!

8.將AllTheColorsOfTheRainbow這個示例改寫成一個程序。

public class AllTheColorsOfTheRainbow {
    int anIntegerRepresentingColors;
    void changeTheHueOfTheColor(int newValue){
        this.anIntegerRepresentingColors = newValue;
    }
}
public class HelloWorld {
    public static void main(String[] args) {
        AllTheColorsOfTheRainbow a = new AllTheColorsOfTheRainbow();
        a.changeTheHueOfTheColor(2);
        System.out.println(a.anIntegerRepresentingColors);
    }
}

返回:2

9.找出HelloDate.java的第二版本,也就是那個簡單注釋文檔的示例。對該文檔執行javadoc,然后通過Web瀏覽器觀看運行結果。

//:HelloDate.java

import java.util.Date;
/**
 * The first Thinking in Java example program.
 * Displays a string and today's date.
 *
 * @author Bruce Eckel
 * @author www.MindView.net
 * @version 4.0
 */
public class HelloDate {
    /**
     * Entrv Doint to class & application
     *
     * @param args array of string arguments
     * @throws exceptions No exceptions thrown
     */
    public static void main(String[] args) {
        System.out.println("Hello, it's: ");
        System.out.println(new Date());
    }
}
/* Output: (55% match)
Hello, it's:
Wed Oct 05 14:39:36 MDT 2005
 *///:~

10.找到第5章中的Overloading.java示例,并為它加入javadoc文檔。然后用javadoc提取此注釋文檔,并產生一個HTML文件,最后,通過Web瀏覽器查看結果。

//: Overloading.java
/**
 * Tree class
 * @author jojo
 * @version 1.0
 */
class Tree {
    /**
     * height
     */
    int height;
    /**
     * Planting a seedling
     */
    Tree() {
        System.out.println("Planting a seedling");
    }
    /**
     * Creating new Tree that is 0 feet tall
     * @param i
     */
    Tree(int i) {
        System.out.println("Creating new Tree that is " + i + " feet tall");
        height = i;
    }
    /**
     * Tree is 0 feet tall
     */
    void info() {
        System.out.println("Tree is " + height + " feet tall");
    }
    /**
     * s : Tree is 0 feet tall
     * @param s
     */
    void info(String s) {
        System.out.println(s + ": Tree is " + height + " feet tall");
    }
}
/**
 * Overloading
 */
public class Overloading {
    public static void main(String[] args) {
        for(int i = 0; i < 5; i++) {
            Tree t = new Tree(i);
            t.info();
            t.info("overloaded method");
        }
        // Overloaded constructor:
        new Tree();
    }
}
//:~

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 五月四房婷婷 | 日本永久免费 | 欧美一级特黄真人毛片 | 久久久久久久久久免费视频 | 国产一区二区久久精品 | 国产情侣偷国语对白 | 国产一级持黄大片99久久 | 欧美αv| 在线免费小视频 | 国产一区二区不卡视频 | 欧美日韩不卡中文字幕在线 | 最猛黑人xxxⅹ黑人猛交 | 久草福利站 | 精品国产免费一区二区三区五区 | 日韩成人国产精品视频 | 日本高清一级片 | 成人综合久久综合 | 亚洲三级中文字幕 | 99在线视频观看 | 99热这里有免费国内精品 | 日韩欧美亚 | 国产精品亚欧美一区二区三区 | 阿v视频在线观看免费播放 阿v天堂2017 | 国产精品久久久香蕉 | 老妇毛片久久久久久久久 | 夜夜骑加勒比 | 天天添天天射 | 亚洲精品美女一区二区三区乱码 | 99re这里有精品 | 久久欧美精品欧美久久欧美 | 性丰满妇女free性性性 | 国产精品久久久久久久久齐齐 | 久热精品视频 | 妖精视频在线观看网站 | 99热爱 | 久久国产视频精品 | 久久99综合国产精品亚洲首页 | 岛国大片在线观看 | 天天干天天干天天干天天 | 在线亚洲黄色 | 中文字幕日本精品一区二区三区 |