zoukankan      html  css  js  c++  java
  • 动手动脑2

    动手动脑1:

    生成随机数算法编写

    package session;

     

    import java.util.Scanner;

     

    public class Random {

        public void random() {

            int n;

            Scanner sc=new Scanner(System.in);

            long seed=System.currentTimeMillis();

            int multiplier=16807;

            int c=0,i;

            long random=(multiplier*seed+c)%Integer.MAX_VALUE;

            System.out.println("请输入生成随机数的数目:");

            n=sc.nextInt();

            for(i=0;i<n;i++) {

                System.out.print(random+" ");

                random=(multiplier*random+c)%Integer.MAX_VALUE;

                if(i%10==0&&i!=0)System.out.println();

            }

        }

        public static void main(String[] args) {

            Random r=new Random();

            r.random();

        }

    }

     运行结果:

    动手动脑2:

    package session;

    //MethodOverload.java

    //Using overloaded methods

     

    public class MethodOverload {

     

        public static void main(String[] args)

        {

            System.out.println("The square of integer 7 is " + square(7));

            System.out.println("\nThe square of double 7.5 is " + square(7.5));

        }

     

        public static int square(int x)

        {

            return x * x;

        }

     

        public static double square(double y)

        {

            return y * y;

        }

    }

    以上代码中使用了方法重载,而构成重载需要满足以下条件:

    (1)      方法名相同。

    (2)      参数类型不同、参数个数不同、参数类型顺序不同(是参数类型不同)。

    注意点:方法的返回值不能作为重载的判断方法。因为在使用同名的方法时时,调用前需要先判断使用哪个方法,而返回值是在调用方法后才会返回,因而返回值不作为重载的判断条件。

  • 相关阅读:
    HBaseTDG ClientAPI The Basics
    Hadoop TDG 3 – MR Features
    NoSQL Data Modeling Techniques
    配置SharePoint 2010的User Profile Synchronization连接到第三方的LDAP服务
    Failed to load data access DLL, 0x80004005
    如何开放HyperV服务的远程连接权限给别人?
    SharePoint 2010 Search 架构 已完工
    如何对SharePoint里OOB的JavaScript文件进行Debug 之一
    UPA Sync Service启动之后立即自动停止
    SharePoint 2010服务器场的防火墙需要开放哪些端口?
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14158452.html
Copyright © 2011-2022 走看看