0
点赞
收藏
分享

微信扫一扫

有参数时有无返回值的调用

zidea 2022-01-12 阅读 55

有参数无返回值的调用

 public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt(); //输入第一个数
			int b = sc.nextInt(); //输入第二个数
	        arr(a,b);
	    }
	  public static void arr(int a,int b){  含有两个参数的方法
	    int d=(a+b)/2;
	    System.out.println("平均数:"+d); //求平均数
	  }

有参数有返回值的调用

 public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();   //输入第一个数
	        int b = sc.nextInt();	//输入第二个数
		        int max=Max(a, b);
				System.out.println( a+"和"+b+"比较,更大的是:"  + max);
		    }
		public static int Max(int a,int b) {
			int max;
			if(a > b){
			    max = a;
			}else{
			    max = b;
		 }
		return max ;
	}
举报

相关推荐

0 条评论