日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java编程思想第四版第三章要点习题

發(fā)布時間:2025/5/22 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java编程思想第四版第三章要点习题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 使用"簡短的" 和正常的 打印語句來編寫一個程序 package net.mindview.util;public class Print {/*** 不帶有回車* @param s*/public static void print(Object s){System.out.print(s);}/*** 帶有回車* @param s*/public static void println(Object s){System.out.println(s);} } package net.mindview.operators;import java.util.Date; import static net.mindview.util.Print.*; public class HelloData {public static void main(String[] args) {print("hello, it is");print(new Date());System.out.println("正常的方式打印");} }

    ?

  • 創(chuàng)建一個包含了float域的類, 并用這個類來展示別名機制. (這里懶得寫了, 就是把demo中的int換成float就可以了) package net.mindview.operators;class Tank{int level; }public class Assignment {public static void main(String[] args) {Tank t1 = new Tank();Tank t2 = new Tank();t1.level = 27;t2.level = 41;System.out.println("t1.level:" + t1.level + ", t2.level:" + t2.level);t2 = t1;System.out.println("t1.level:" + t1.level + ", t2.level:" + t2.level);t1.level = 5;System.out.println("t1.level:" + t1.level + ", t2.level:" + t2.level);}}

    ?

  • 創(chuàng)建一個包含一個float域的類, 并用這個類來展示方法調用時的別名機制(將char改為float即可) package net.mindview.operators;class Letter{char c; }public class PassObject {static void f(Letter y){y.c = 'z';}public static void main(String[] args) {Letter x = new Letter();x.c = 'a';System.out.println("1: x.c="+x.c);//傳遞的時x所指向的引用 f(x);System.out.println("1: x.c="+x.c);} }

    ?

  • 編寫一個計算速度的程序, 壓縮使用的距離和時間都是常量.(略)
  • 創(chuàng)建一個名為Dog的類, 他包含兩個String與:name和says。 在main()方法中,創(chuàng)建兩個Dog對象, 一個名為spot(它的叫聲為ruff!),另一個名為scruffy(它的叫聲為Wurf!).然后顯示他們的名字和叫聲。 package net.mindview.operators;class Dog{public String name;public String says;@Overridepublic String toString() {return "名字:"+this.name + ",語言:"+this.says;} } public class DogTest {public static void main(String[] args) {// TODO Auto-generated method stubDog d1 = new Dog();Dog d2 = new Dog();d1.name = "spot";d1.says = "Ruff!";d2.name = "scruffy";d2.says = "Wurf!";System.out.println(d1);System.out.println(d2);} }

    ?

  • 在練習5的基礎上,創(chuàng)建一個新的Dog對象, 并對其賦值為spot對象。測試==和equals()方法來比較所有引用的結果。 package net.mindview.operators;class Dog{public String name;public String says;@Overridepublic String toString() {return "名字:"+this.name + ",語言:"+this.says;} } public class DogTest {public static void main(String[] args) {// TODO Auto-generated method stubDog d1 = new Dog();Dog d2 = new Dog();d1.name = "spot";d1.says = "Ruff!";d2.name = "scruffy";d2.says = "Wurf!";System.out.println(d1);System.out.println(d2);Dog d3 = new Dog();d3.name = "spot";System.out.println(d1.name == d3.name);System.out.println(d1.name.equals(d3.name));} }

    輸出結果:

    名字:spot,語言:Ruff! 名字:scruffy,語言:Wurf! true true

    這個結果需要特別說明一下, String是特殊的引用類型, 當他被直接賦值時,就是把這個值對應的引用位置賦值給String變量了, 所以, 兩次結果都是true。 如果你用new String()賦值, 結果就不同了.

  • 編寫一個程序, 模擬扔硬幣的結果 package net.mindview.operators;import java.util.Random; import static net.mindview.util.Print.*; public class ThrowCron {public static void main(String[] args) {Random num = new Random();int a = num.nextInt(100);switch (a % 2){ case 0:println("正面"); break;case 1:println("反面");break;}}}

    ?

  • fadsfas
  • fasfda
  • fasdf
  • fasdfa
  • fasdf
  • fasd
  • fdasf
  • fadsf
  • 轉載于:https://www.cnblogs.com/ITPower/p/8509809.html

    總結

    以上是生活随笔為你收集整理的java编程思想第四版第三章要点习题的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。