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();
}
}
記得給分,有問題請追問