zoukankan      html  css  js  c++  java
  • 动手动脑

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

    源代码:

    package lianxi;

    import java.util.*;

    public class Suijishu {

       public static int n;

       public static void main(String[] args) {

          // TODO 自动生成的方法存根

          System.out.println("请输入要生成的随机数个数:");

          Scanner sc=new Scanner(System.in);

          n=sc.nextInt();

          Suijishu A=new Suijishu();

          A.creat();

       }

       public void  creat()

       {

          Random rand=new Random();

          int[] a=new int[n];

          for(int i=0;i<n;i++)

          {

             int x=rand.nextInt(100);//随机产生1——100的 一个种子

             int seed=(7^5*x+0)%(2147483647-1);

             System.out.print(seed+" ");

          }

       }

    }

     截图:

    2.请看以下代码,发现了什么特殊之处?

    答:都运用了函数调用,传递形参的方式,两个函数名相同,但是函数传递的参数类型不同。

    3.写n的阶乘的程序

    源代码:

    package lianxi;

    import java.util.*;

    public class jiecheng {

       public static int n,result;

       public static void main(String[] args) {

          System.out.println("输入正整数n");

          Scanner sc=new Scanner(System.in);

          n=sc.nextInt();

            jiecheng A=new jiecheng();

            result=A.jisuan(n);

            System.out.println("n!="+result);

       }

       public int jisuan(int x)

       {

          if(x==0||x==1)

          return 1;

          else

             return x*jisuan(x-1);

       }

    }

     截图:

  • 相关阅读:
    java 调用摄像头拍照
    jenkins docker sop
    springboot多环境打包
    docker构建nginx
    docker 构建jdk-tomcat基础镜像
    docker 构建jar 镜像
    docker 构建springmvc war项目
    centos 启动jar脚本
    nginx dockerfile
    Starting zookeeper ... FAILED TO START
  • 原文地址:https://www.cnblogs.com/zzh2019979439/p/7660581.html
Copyright © 2011-2022 走看看