JAVA笔记:JAVA程序控制

public class HelloWorld{
	public String fun()
	{
		return "利用return返回值";
	}
	public void message(int i){
		if(i == 1)
		{
			System.out.println("发送短信");
			return; //结束方法的运行
		}
		if(i == 2)
		{
			System.out.println("复制短信");
			return; //结束方法的运行
		}
		if(i == 3)
		{
			System.out.println("粘贴短信");
			return; //结束方法的运行
		}
	}
	public static void main(String[] args){
		System.out.println("Hello,World!");
		//循环中各种类型均可
		for(int i = 0;i<10;i++){}
		for(short i = 0;i<10;i++){}
		for(char i = 0;i<10;i++){}
		for(byte i = 0;i<10;i++){}
		for(double i = 0;i<10;i++){}
		//for(;;){}
		//死循环 等价于 while (true),等价于 boolean flag = false
		//增强型for循环
		int a[] = {1,2,3,4,5}; // 如果赋值为null ,则提示空指针,报错;
		for(int m:a)
		{
			System.out.println(m);
		}
		
		//switch语句
//		switch(表达式) {
//			case 值1:
//			//body
//				break;
//			case 值2:
//			//body
//				break;
//				…………………
//			default:
//			//body
//		}
//		
		
		//多重循环的控制
		xx:for(int i=0;i<4;i++)
		{
			yy:for(int j=0;j<4;j++)
			{
				if(j==3)
					break xx;
			}
		}
		
		
		//利用return返回值
		HelloWorld obj = new HelloWorld();
		String m = obj.fun();
		System.out.println(m);
		
		//message方法的使用
		HelloWorld obj1 = new HelloWorld();
		obj.message(1);//传值1给message方法
		
		
	}
	
	
	
}



java类型转换:1.占用字节少的一般转换成占用字节多的类型

2.字符类型会转换成int类型

3.int类型会转换成float类型

4.若表达式中某个操作类型为double,则另一个也会转换成double类型

5.布尔类型不能转换成其他类型

原文地址:https://www.cnblogs.com/tryitboy/p/4231153.html