• 作业 回文和重载


    1 重载问题

    public class MethodOverload {
    
    	public static void main(String[] args) {
    		System.out.println("The square of integer 7 is " + square(7));
    		System.out.println("
    The 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)参数类型不同,参数个数不同,或者是参数类型的顺序不同。

    2 随机数生成器

    package 随机数生成器;
    
    public class Shuiji {
    public static void main(String[] args) {  
    
        int n=1000;
    
        Creat(n);
    
      }
      static BigInteger Creat(int n) {
        BigInteger result;
        if(n==1) {;
          result=BigInteger.valueOf((int)Math.random()*100000+1);
          System.out.println("第1个随机数是"+result);
          return result;
        }
        else {
          BigInteger i=Creat(n-1).multiply(BigInteger.valueOf(16807));
          result=i.mod(BigInteger.valueOf(Integer.MAX_VALUE));Creat(n-
          System.out.println("第"+n+"个随机数是"+result);
          return result;
        }
      }
    
    }
    

      

    3  JDK中System.out.println()方法:

    System.out.println()方法有很多种重载,如char,int,long,string等等,当不调用参数时,其输出换行符。

      

  • 相关阅读:
    3.24
    3.23
    构建之法读书笔记2
    寒假学习day23
    寒假学习day22
    寒假学习day21
    寒假学习day20
    寒假学习day19
    寒假学习每周总结4
    寒假学习day18
  • 原文地址:https://www.cnblogs.com/xuange1/p/9784477.html
Copyright © 2020-2023  润新知