专注Java教育14年 全国咨询/投诉热线:444-1124-454
星辉LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 Java编程思想源码

Java编程思想源码

更新时间:2021-05-07 10:58:34 来源:星辉 浏览682次

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();
	}	
}

以上就是星辉小编介绍的"Java编程思想源码"的内容,希望对大家有帮助,如有疑问,请在线咨询,有专业老师随时为您服务。

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>