黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

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

部分Java編程思想答案

更新時(shí)間:2022-03-24 11:02:31 來源:動(dòng)力節(jié)點(diǎn) 瀏覽1524次

1.創(chuàng)建一個(gè)類,它包含一個(gè)int域和一個(gè)char域,它們都沒有被初始化,將它們的值打印出來,以驗(yàn)證Java執(zhí)行了默認(rèn)初始化。

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.編寫一個(gè)程序,讓它含有本章所定義的storage()方法的代碼段,并調(diào)用之。

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的代碼改寫成一個(gè)完整的可運(yùn)行程序。

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.編寫一個(gè)程序,展示無論你創(chuàng)建了某個(gè)特定類的多少個(gè)對(duì)象,這個(gè)類中的某個(gè)特定的static域只有一個(gè)對(duì)象。

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.編寫一個(gè)程序,展示自動(dòng)包裝功能對(duì)所有的基本類型和包裝器類型都起作用。

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.編寫一個(gè)程序,打印出從命令行獲取的三個(gè)參數(shù)。為此,要確定命令行數(shù)組中String的下標(biāo)。

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這個(gè)示例改寫成一個(gè)程序。

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的第二版本,也就是那個(gè)簡(jiǎn)單注釋文檔的示例。對(duì)該文檔執(zhí)行javadoc,然后通過Web瀏覽器觀看運(yùn)行結(jié)果。

//: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提取此注釋文檔,并產(chǎn)生一個(gè)HTML文件,最后,通過Web瀏覽器查看結(jié)果。

//: 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();
    }
}
//:~

 

提交申請(qǐng)后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 国产特黄一级毛片特黄 | 成人欧美一区二区三区在线观看 | 吃奶呻吟打开双腿做受动态图 | 无遮挡一级毛片私人影院 | 欧美日韩高清在线观看一区二区 | 亚洲日本免费 | 97夜夜操| 欧美日韩精 | 在线播放 亚洲 | 成人va| 亚洲黄色大片 | 国产免费好大好硬视频 | 在线观看视频你懂得 | 亚洲国产精久久小蝌蚪 | 美女黄站 | 丁香婷婷综合五月综合色啪 | 在线视频一区二区三区在线播放 | 黄色免费毛片 | 成人午夜视频免费看欧美 | 亚洲国产最新在线一区二区 | 午夜小视频男女在线观看 | 中文字幕日本精品一区二区三区 | 日韩精品中文字幕一区三区 | 亚洲一区二区三区精品国产 | 国产乱人视频在线播放不卡 | 高清色惰www日本午夜 | 污视频免费在线播放 | 日韩18在线观看 | 日韩午夜在线视频 | 免费网站在线观看国产v片 免费网站看v片在线成人国产系列 | 九九久久精品这里久久网 | 成人久久久精品乱码一区二区三区 | 特一级毛片 | 伦理网站在线播放视频 | 日韩一区在线视频 | 国产一级成人毛片 | 亚洲黄色小视频 | 亚洲国产日韩欧美在线a乱码 | 天天色综合3 | 狠狠色婷婷丁香六月 | 伊人久久免费视频 |