自动生成数字的小程序怎么写?

自动生成数字的小程序怎么写?,第1张

package javaIO

public class Aoao {

public void ten(){

int a[]= new int[7]

int temp

//srand( (unsigned)time( NULL ) )

int i=0

boolean s=true

while(i<7)

{

temp=(int) Math.abs(Math.random()*32)+1

if (i==6)

temp=(int) Math.abs(Math.random()*16)+1

s=true

for(int j=0j<ij++) //判断有没有重复

{

if (a[j]==temp)

s=false}

if (s){

a[i]=temp i++}

}

for (i=0i<7i++){

System.out.print(a[i]+" ")

}

}

public static void main(String [] args){

Aoao ao = new Aoao()

ao.ten()

}

}

错误有点小多,不过熟能生巧 修改如下

#include <stdio.h>//这里修改成 <>包含头文件 

#include <math.h>

int main() //这里加上 int main() ,每个c/c++程序必须有一个主函数

{

double a,b,c,x1,x2,q,p,disc

scanf("%f%f%f",&a,&b,&c) //这里加上逗号

disc= b*b - 4*a*c

if(disc<0)//这里修改为disc 而不是你源码中的dics 去掉语句结束符

printf("This equation hasnt a real roots\n")

else

{

p=a/2.0*a

q=sqrt(disc)/2.0*a//sqrt是函数需要sqrt(disc)这样调用

x1=q+p,x2=q-p

printf("real roots:\n%7.2f\n%7.2f",a,b)

}

return 0

}

观楼主英俊潇洒,风流倜傥,必当世豪杰,大侠闲暇之余,关注0x30百度贴吧,必成千秋霸业,建不世之功。

1、可以使用随机函数来规定抽签结果,比如:Math.random(),这个函数会返回一个0到1之间的随机小数。

2、也可以使用其他的算法,比如洗牌算法,从一组数据中随机抽取一个元素,可以保证抽签结果的公平性。

3、还可以使用一些智能算法,如机器学习算法,根据历史数据来计算抽签结果,可以有效地避免抽签中出现的偏差。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7884312.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存