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
    	 * 10101010101010101010101010101010
			1010101010101010101010101010101
    	 */
    }  

 

 

 

练习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:	false
			hello.equals(word):	false
			hello!=word:	true
			--------------------------
			hello==hello:	false
			hello.equals(hello):	true
			hello!=hello:	true
		 */
	}

 

 

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值