现在的位置: 首页 > 综合 > 正文

java语言函数部分实列附加代码截图-作者:逝秋

2018年05月03日 ⁄ 综合 ⁄ 共 527字 ⁄ 字号 评论关闭
class Demo
		{
			public static void main(String[] args)
			{
				int l=mini(8,3);
				prints(9,23);
				byte a=3;
				byte b=92;
				int c = fanhui(a,b);
				System.out.println("测试返回值类型是否与接收值类型有关"+c);

				System.out.println("打印两数之和:"+l);
			}
			public static int mini(int a,int b)
			{
				a+=b;
				return a;
			}
			public static void prints(int a ,int b)//比较两个数中最大值,直接打印无需返回参数。
			{
				if(a>b)
				{
					System.out.println("比较两个数中最大值:"+a+">"+b);//无需返回值类型,可以省略return;语句
				}
				else if (a<b)
				{
					System.out.println("比较两个数中最大值:"+a+"<"+b);
				}
				else 
				{
					System.out.println("两个数相等:"+a+"="+b);
				}
			}
			public static int fanhui(byte a ,byte b)//返回值类型与参数类型无关
			{
				a+=b;
				return a;
			}
		}

运算结果:

 

 

 

抱歉!评论已关闭.