zoukankan      html  css  js  c++  java
  • 2019.09.23课堂总结

    一、动手动脑1

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

    代码如下:

     1 import java.util.Scanner;
     2 
     3 public class Random {
     4     private static Scanner sc = new Scanner(System.in);
     5 
     6     public static void main(String[] args) {
     7         System.out.println("请输入想要生成的随机数的个数:");
     8         int n = 0;
     9         n = sc.nextInt();
    10         System.out.println("生成的随机数为:");
    11         int x = 10;
    12         for (int i = 1; i <= n; i++) {
    13             x = (7 ^ 5 * x + 0) % 2147483647;
    14             System.out.print(x + "	");
    15             if (i % 5 == 0) {
    16                 System.out.println("");
    17             }
    18         }
    19     }
    20 }

    运行截图:

     二、动手动脑2

    请看以下代码,你发现了有什么特殊之处吗?

     1 // MethodOverload.java
     2 // Using overloaded methods
     3 
     4 public class MethodOverload {
     5 
     6     public static void main(String[] args) {
     7         System.out.println("The square of integer 7 is " + square(7));
     8         System.out.println("
    The square of double 7.5 is " + square(7.5));
     9     }
    10 
    11     public static int square(int x) {
    12         return x * x;
    13     }
    14 
    15     public static double square(double y) {
    16         return y * y;
    17     }
    18 }
    View Code

    上述代码展示了Java方法重载的特性,满足以下条件的两个或多个方法构成重载关系:

    (1)方法名相同;

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

  • 相关阅读:
    【转】JSP三种页面跳转方式
    我要从头做起
    转载:用 Tomcat 和 Eclipse 开发 Web 应用程序
    html的style属性
    Java连接oracle数据库
    tomcat遇到的问题(总结)
    ceshi
    今天要小结一下
    argument.callee.caller.arguments[0]与window.event
    JavaScript事件冒泡简介及应用
  • 原文地址:https://www.cnblogs.com/best-hym/p/11588732.html
Copyright © 2011-2022 走看看