zoukankan      html  css  js  c++  java
  • Java学习的第四十一天

    1.例4.4内置函数

    public class cjava {
        public static void main(String[] args) {
    int i=10,j=20,k=30,m;
    m=max(i,j,k);
    System.out.println("max="+m);
        }
        final static int max(int a,int b,int c) {
            if(b>a)
                a=b;
            if(c>a)
                a=c;
            return a;
        }
    }

     例4.5重载函数(参数类型)

    import java.util.Scanner;
     public class cjava {
         public static void main(String[] args) {
             int i1,i2,i3,i;
             @SuppressWarnings("resource")
            Scanner a=new Scanner(System.in);
             i1=a.nextInt();
             i2=a.nextInt();
             i3=a.nextInt();
             i=max(i1,i2,i3);
             System.out.println("max="+i);
             double d1,d2,d3,d;
            d1=a.nextDouble();
             d2=a.nextDouble();
             d3=a.nextDouble();
             d=max(d1,d2,d3);
             System.out.println("max="+d);
             long g1,g2,g3,g;
             g1=a.nextLong();
             g2=a.nextLong();
             g3=a.nextLong();
             g=max(g1,g2,g3);
             System.out.println("max="+g);
         }     static int max(int a,int b,int c) {
             if(b>a) a=b;
             if(c>a) a=c;
             return a;
         }
         static double max(double a,double b,double c) {
             if(b>a) a=b;
             if(c>a) a=c;
    return a;
         }
         static long max(long a,long b,long c) {
             if(b>a) a=b;
             if(c>a) a=c;
             return a;
         } 
    }

     例4.6函数重载(参数个数)

     public class cjava {
         public static void main(String[] args) {
             int a=8,b=-12,c=27;
             System.out.println("max(a,b,c)="+max(a,b,c));
             System.out.println("max(a,b)="+max(a,b));
         } 
         static int max(int a,int b,int c) {
             if(b>a)
                 a=b;
             if(c>a)
                 a=c;
             return a;
         }
         static int max(int a,int b) {
             if(b>a)
                 a=b;
             return a;
         }
    }

     2.没问题。

    3.明天继续写例题。

  • 相关阅读:
    Shiro权限验证
    5种设计模式整理
    多模块的SpringBoot项目
    Go使用数据库
    使用Go mod
    docker基本使用
    Go的IO操作
    实现一个网盘存储……
    Go的网络编程
    学习golang的历程
  • 原文地址:https://www.cnblogs.com/feng747/p/13514115.html
Copyright © 2011-2022 走看看