java語言函數部分實列附加代碼截圖-作者:逝秋

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

運算結果:

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章