java编程思想 -类型转换操作符,截尾和舍入,Foreach语法,tocharArray,位移操作符,三元操作符,操作符+ 和+=*

package day2;



/**
 * 
 * @author duhongyu  2018年11月23日
 * 类型转换操作符
 *
 */
public class Casting {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			int i = 200;
			long lng = (long)i;
			lng = i;//widening so cast no really required
			long lng2 = (long)200;
			lng2 = 200;
			i = (int)lng2;
			
	}

}

package day2;

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

/**
 * 
 * @author duhongyu  2018年11月23日
 * 截尾和舍入
 *
 */
public class CastingNumbers {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double above = 0.7,below = 0.4;
		float fabove = 0.7f,fbelow = 0.4f;
		print("(int)above:"+(int)above);
		print("(int)above:"+(int)below);
		print("(int)fabove:"+(int)fabove);
		print("(int)fbelow:"+(int)fbelow);
	}

}

package day2;

import java.util.Random;

/**
 * 
 * @author duhongyu  2018年11月23日
 * Foreach语法
 *
 */
public class ForEacheFloat {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Random rand = new Random(47);
		float f[] = new float[10];
		
		for(int i = 0;i<10;i++)
			f[i] = rand.nextFloat();
		for(float x: f)
			System.out.println(x);
	}

}

package day2;

/**
 * 
 * @author duhongyu  2018年11月23日
 * tocharArray
 *
 */
public class ForEachString {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(char c :"An China fly ".toCharArray())
		{
			System.out.print(c+" ");
		}
	}

}

package day2;

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

/**
 * 
 * @author duhongyu  2018年11月23日
 *	if-else
 *
 */
public class IfElse {

	static int result = 0;
	static void test(int testval,int target) {
		if(testval>target)
			result = +1;
		else if (testval <target)
			result = -1;
		else result = 0;
		
		
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		test(10,5);
		print(result);
		test(5,10);
		
		print(result);
		test(5,5);
		print(result);
		
		
		
	}

}

package day2;
/**
 * 
 * @author duhongyu  2018年11月23日
 *  for 循环
 *
 */
public class ListCharacters {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		 for (char c = 0 ;c<128;c++)
		 {
			 if(Character.isLowerCase(c)) {
				 System.out.println("value:"+(int)c+"   character:"+c);
			 }
			 
			 
		 }

	}

}

package day2;

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

/**
 * 
 * @author duhongyu  2018年11月23日
 * 操作符+  和+=*
 */
public class StringOperators {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int x = 0,y = 1, z= 2;
		String s = "x,y,z";
		print(s+x+y+z);
		print(x+ " "+s); ///Converts x to a String
		s +="(sumed) = ";
		print(s+(x+y+z));
		print(""+x);
	}

}

package day2;

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

/**
 * 
 * @author duhongyu  2018年11月23日
 * 三元操作符 if-else
 *
 */
public class TernaryIfElse117 {

	static int ternary(int i) {
		return i<10?i*100:i*10;
	}
	
	static int standardIfElse(int i) {
		if(i < 10)
			return i*100;
		else
			return i*10;
		
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		print(ternary(9));
		print(ternary(10));
		print(standardIfElse(9));
		print(standardIfElse(10));
		
		
	}

}

package day2;

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

/**
 * 
 * @author duhongyu  2018年11月23日
 *位移操作符
 *
 */
public class URShift112 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int i = -1;
		print(Integer.toBinaryString(i));
		i >>>= 10;
		print(Integer.toBinaryString(i));
		long l = -1;
		print(Long.toBinaryString(l));
		l >>>= 10;
		print(Long.toBinaryString(l));
		short s = -1;
		print(Integer.toBinaryString(s));
		s >>>= 10;
		print(Integer.toBinaryString(s));
		byte b = -1;
		print(Integer.toBinaryString(b));
		b >>>= 10;
		print(Integer.toBinaryString(b));
		b = -1;
		print(Integer.toBinaryString(b));
		print(Integer.toBinaryString(b>>>10));
		
		
		
	}

}

package day2;
/**
 * 
 * @author duhongyu  2018年11月23日
 * 迭代
 *
 */
public class WhileTest {

	static boolean condition() {
		
		boolean result =Math.random()<0.99;
		System.out.println(result+". ");
		return result;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		while(condition())
			System.out.println("Inside 'while;");
			System.out.println("Exited 'while'");
		
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值