zoukankan      html  css  js  c++  java
  • Java-02-动手动脑

    1.设计思想:利用随机数产生公式,递归调用,输出一定数量的随机数。

    2.源代码:

    import java.util.Scanner;
    
    public class Suiji_2 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner in = new Scanner(System.in);
            System.out.println("产生随机数数量:");
            int m=in.nextInt();
            System.out.println("input c:");
            int c=in.nextInt();
            suiji(m,c);
        
        }
          public static void suiji(int m,int c)
          {
                int a=1;
                int x=(2^10000)-1;
                for(int i=1;i<=m;i++)
                {
                    a=((7^5)*a+c)%x;
                    System.out.print(a+"    ");
                    if(i%10==0){System.out.println();}
                }
          }
    }

    3.程序截图:

     

    1.程序代码:

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

    2.回答:

    代码中的两个方法,方法名相同,但返回值类型和参数类型都不同,这就是方法的重载。

    方法重载要求:

    (1)方法名相同;
    (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。

    注意:方法的返回值不作为方法重载的判断条件!

     
  • 相关阅读:
    HDU 5528 Count a * b 欧拉函数
    HDU 5534 Partial Tree 完全背包
    HDU 5536 Chip Factory Trie
    HDU 5510 Bazinga KMP
    HDU 4821 String 字符串哈希
    HDU 4814 Golden Radio Base 模拟
    LA 6538 Dinner Coming Soon DP
    HDU 4781 Assignment For Princess 构造
    LA 7056 Colorful Toy Polya定理
    LA 6540 Fibonacci Tree
  • 原文地址:https://www.cnblogs.com/lxy10375/p/7663608.html
Copyright © 2011-2022 走看看