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; } }
运算结果: