动手动脑2

package we;


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

 

动手动脑: 编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数。

package we;

import java.util.Random;
import java.util.Scanner;

public class we
{
public static void main(String[] args)
{

Random x = new Random(System.currentTimeMillis());
System.out.println("随机数数量");
int y;
Scanner in = new Scanner(System.in);
y= in.nextInt();
for(int i=0;i<y;i++)
System.out.println( x.nextInt());

}
}

文件导入

 InputStream fis = new FileInputStream("d:" + File.separator + "test.txt");
byte[] buf = new byte[1024]; int len;
 String myStr = ""; while((len = fis.read(buf)) != -1)


 
 
 
posted @ 2019-09-27 19:12  明月照我还  阅读(91)  评论(0编辑  收藏  举报