作业 回文和重载

1 重载问题

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)参数类型不同,参数个数不同,或者是参数类型的顺序不同。

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等等,当不调用参数时,其输出换行符。

  

posted on 2018-10-13 22:16  冰雨xuange  阅读(93)  评论(0编辑  收藏  举报

导航