Java編程思想第四版 第三章個人練習,編程思想第四版

來源:互聯網
上載者:User

Java編程思想第四版 第三章個人練習,編程思想第四版

希望大家給予批評指正,在下感激不盡(未完,待續……)
第三章練習9 (1)分別顯示用float和double指數記數法所能表示的最大和最小數字


public class MaxMinFloatDouble {              /**       * @param args       */      public static void main(String[] args) {           // TODO Auto-generated method stub           float fmax = Float.MAX_VALUE;           float fmin = Float.MIN_VALUE;           double dmax = Double.MAX_VALUE;           double dmin = Double.MIN_VALUE;                      System.out.println(fmax);           System.out.println(fmin);           System.out.println(dmax);           System.out.println(dmin);                      /*result:          3.4028235E38          1.4E-45          1.7976931348623157E308          4.9E-324*/      }   }

練習(10)編寫一個具有兩個常量值的程式,一個具有交替的二進位位1和0,其中最低有效位為0,另一個也具有交替的二進位位1和0,但其最低有效位為1(提示:使用十六進位常量來表示最簡單的方法).取兩個值,用按位操作符以所有可能方式結合運算它們,然後用Integer.toBinaryString()顯示
    public static void main(String[] args) {       int i1 = 0xaaaaaaaa;     int i2 = 0x55555555;     System.out.println(Integer.toBinaryString(i1));    System.out.println(Integer.toBinaryString(i2));    /**     * result     * 101010101010101010101010101010101010101010101010101010101010101     */    }  

練習14 (3)編寫一個接收兩個字串參數的方法,用各種布爾值的比較關係來比較這兩個字串,然後把結果列印出來。做==和!=的同時,用equals()作測試。在main()裡面用幾個不同的字串對象調用這個方法。
         /** * @param args */public static void main(String[] args) {String str1="hello";String str2="word";String str3=new String("hello");testStr(str1, str2);System.out.println("--------------------------");testStr(str1, str3);}public static void testStr(String s1,String s2){//boolean b1=s1>s2;//boolean b2=s1<s2;boolean b3=s1==s2;System.out.println(s1+"=="+s2+":\t"+b3);boolean b4=s1.equals(s2);System.out.println(s1+".equals("+s2+"):\t"+b4);boolean b5=s1!=s2;System.out.println(s1+"!="+s2+":\t"+b5);/**result *  *  hello==word:falsehello.equals(word):falsehello!=word:true--------------------------hello==hello:falsehello.equals(hello):truehello!=hello:true */}





誰有java編程思想第四版的練習答案

無人作答,還是加入關於JAVA的QQ群或是直接加入這書的群吧。他們會有答案。我也是愛好者,這是我的建議採納吧!
 
哪位買了Thinking in Java中文版JAVA編程思想 第四版,第37頁練習3找出含有ATYPENAME的代碼斷是什

答案的電子版和代碼已發送請查收

// TIJ4 Chapter Object, Exericise 3, page 90
// object/ATNTest.java
// Find the code fragments involving ATypeName and turn them into a program
// that compiles and runs.
你的問題答案
public class ATNTest {
public static void main(String[] args) {
class ATypeName {
int i;
double d;
boolean b;
void show() {
System.out.println(i);
System.out.println(d);
System.out.println(b);
}
}
ATypeName a = new ATypeName();
a.i = 3;
a.d = 2.71828;
a.b = false;
a.show();
}
}
記得給分,有問題請追問
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.