java编程思想--书中源码

import static net.mindview.util.Print.*;

/**
 * 
 * @author duhongyu  2018年11月22日
 *
 *
 */
public class AutoInc {
	public static void main(String[] args) {
		int i = 1;
		print("i :"+i);
		print("++i"+ ++i); //Pre_increment;
		print("i++" +i++); //Post_increment;
		print("i :"+i);
		print("--i"+ --i);
		print("i--"+i--);
		print("i :"+i);
		
		
	}

}

/**
 * 
 * @author duhongyu  2018年11月22日
 *
 *
 */
public class EqualsMethod {
	
	public static void main(String[] args) {
		Integer  n1 = new Integer(47);
		Integer  n2 = new Integer(47);
		
		System.out.println(n1.equals(n2));
	}
}


/**
 * 
 * @author duhongyu  2018年11月22日
 *
 *
 */
import static net.mindview.util.Print.*;

//测试对象的等价性
public class Equivalence {

	public static void main(String[] args) {
		
		Integer n1 = new Integer(47);
		Integer n2 = new Integer(47);
		
		print(n1==n2);
		
		print(n1!=n2);
		
		
	}
}

import static net.mindview.util.Print.*;


public class Literals {
 public static void main(String[] args) {
	int i1 = 0x2f;
	print("i1"+Integer.toBinaryString(i1));
	int i2 = 0X2F;
	print("i2"+Integer.toBinaryString(i2));
	
	int i3 = 0177;
	print("i3"+Integer.toBinaryString(i3));
	
	char  c = 0xffff;
	print("C:"+Integer.toBinaryString(c));
	byte b = 0x7f;
	print("b:"+Integer.toBinaryString(b));
	short s =0x7fff;
	print("s:"+Integer.toBinaryString(s));
	long n1 = 200L;
	long n2 = 200l;
	long n3 = 200;
	float f1 = 1;
	float f2 =1F;
	float f3 = 1f;
	double d1 = 1d;
	double d2 =1D;
	
	
	
	 
	 
	 
	 
	 
}
}

import java.util.Random;

import static net.mindview.util.Print.*;

/**
 * 
 * @author duhongyu  2018年11月22日
 *
 *
 */
public class MathOps {

	public static void main(String[] args) {
		//create a seeder random number generator
		Random rand = new Random(47);
		
		int i,j,k;
		//choose value from 1 to 100
		j = rand.nextInt(100)+1;
		print("j :"+j);
		k = rand.nextInt(100)+1;
		print("k :"+k);
		i = j+k;
		print("j+k:"+i);
		
		i = j-k;
		print("j-k;"+i);
		i = k/j;
		print("k/j:"+i);
		i = k*j;
		print("k*j"+i);
		i = k%j;
		print("k%j"+i);
		j %= k;
		print("j % k:"+j);
		//Floating-point number tests
		
		float u,v,w;
		v = rand.nextInt();
		print("v:"+v);
		w = rand.nextFloat();
		print("w"+w);
		u = v+ w;
		print("v+w:"+u);
		u = v-w;
		print("v-w:"+u);
		u = v*w;
		print("v*w:"+u);
		u = v/w;
		print("v/w:"+u);
		u+=v;
		print("u+=v:"+u);
		u-=v;
		print("u-=v:"+u);
		u*=v;
		print("u*=v:"+u);
		u/=v;
		print("u/=v:"+u);
		
		
		
		
		
		
	}
}

import static net.mindview.util.Print.*;
/**
 * 
 * @author duhongyu  2018年11月22日
 *
 *
 */
public class ShortCircult {
	
	static boolean test1(int val) {
		print("test1("+val+")");
		print("result : "+(val <1 ));
		return val<1;
	}
	
	static boolean test2(int val) {
		print("test2("+val+")");
		print("result : "+(val <2 ));
		return val<2;
	}
	
	static boolean test3(int val) {
		print("test3("+val+")");
		print("result : "+(val <3 ));
		return val<3;
	}
	
	public static void main(String[] args) {
		boolean b = test1(0)&&test2(2)&&test3(2);
		print("expression is " + b);
	}
}




public class test5 {
	
	public static void main(String[] args) {
		
		
		Dog dog1 = new Dog();
		dog1.name = "spot";
		dog1.says ="Ruff";
		Dog dog2 = new Dog();
		dog2.name = "scruffy";
		dog2.says = "Wurf";
		
		System.out.println(	"spot.says----" +dog1.says);
		System.out.println("scruffy.says---"+dog2.says);
		
	}
	
	
	

}
class Dog{
	String name;
	String says;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSays() {
		return says;
	}
	public void setSays(String says) {
		this.says = says;
	}
	public Dog() {
		super();
	}
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值