33问答网
所有问题
当前搜索:
java在一个范围内生成随机数
Java随机数
,种子
范围
为-5到+5
答:
//ramdom:
随机数
(0-
1
)//maxValue:
范围
的最大值 //minValue:范围的最小值 random * (maxValue - minValue) + minValue
JAVA
中
生成
正负
随机数
问题?
答:
public static void main(String[] args) { int a=(int)(Math.random()*2+
1
);int aa=(int)(Math.pow(-1, a));System.out.println(aa);int aaa=(int)(Math.random()*100+1);int num=aa*aaa;System.out.println(num);if(num>0){ System.out.println("正数");}else if(num<0)...
JAVA
编写
一个
Applet,
生成
100个
随机数
,统计小于和不小于0.5的数各有多...
答:
import
java
.awt.*;import javax.swing.*;public class NumApplet extends JApplet{ int n1=0,n2=0;public void init(){ for(int i=0;i<100;i++){ if(Math.random()<0.5)n1++;else n2++;} } public void paint(Graphics g){ g.drawString("小于0.5的有"+n1+"个",50,50);g....
在
java
中
随机生成
10个整数,用户求输入
一个数
,判断是否存在于这10个...
答:
由于你没有指定这10个整数的
生成范围
,所以我这里假定是0~99之间的整数,这样用户输入时有10%的几率命中。整体代码为:public class Main {public static void main(String[] args) {//声明长度为10的
随机数
数组int[] randoms = new int[10];Random random = new Random();for (int i = 0;...
...要求添加5个按钮和
一个
显示窗口能够
生成随机数
!急急急!!!
答:
import javax.swing.JFrame;import javax.swing.JOptionPane;public class DataAdd extends JFrame implements ActionListener{ JButton aButton=new JButton("按钮
1
");JButton bButton=new JButton("按钮2");JButton cButton=new JButton("按钮3");JButton butnRan=new JButton("
生成随机数
");J...
用
java创建一个
含50个元素的数组,并用1~50的
随机数
进行初始化。
答:
主要是Random的使用 public class RandomTest { public static void main(String[] args) { int max=50; int min=
1
; int[] ra = new int[50]; Random random = new Random(); for (int i=0; i<50; i++) { int s = random.nextInt(max)%(max-min+1) + ...
Java
编程:
生成
一些
随机数
,
一个
线程负责将随机数压到队列
里
,另外一个线...
答:
private Queue<Integer> queue;public RandomNumQueue(){queue = new LinkedList<Integer>();} public void run(){ int randomNumber;new inerThread().start(); //第二个负责取数据的线程启动 while(true){ randomNumber = (int)(Math.random()*100); //
产生
0-100的
随机数
queue.offer(...
JAVA
利用
随机
函数
产生
36个10~30之间的整数给
一个
6*6的矩阵赋值._百度...
答:
public static void main(String[] args) throws Exception { Random r=new Random();int max=0;int[][] shus=new int[6][6];for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ //获取10-30的
随机数
int shu=r.nextInt(20)+10;shus[i][j]=shu;if(...
Java
用random 从一个数组中选
一个数
答:
我们看看API中对nextInt(int)方法的解释:nextInt(int n)返回一个伪随机数,它是取自此
随机数生成
器序列的、在 0(包括)和指定值(不包括)之间均匀分布的 int 值。select.nextInt(theAnimals.length)的作用是
生成一个
不超过数组长度的整数,而不是生成下一个数组长度的整数!
请用
Java
建立
一个
3*3的三维数组,数组值使用
随机数生成
,其
范围
是1~5...
答:
s1/3;double h2=(double)s2/3;double h3=(double)s3/3;System.out.println("第一行和为:"+s1+"\t其平均数为:"+h1);System.out.println("第一行和为:"+s2+"\t其平均数为:"+h2);System.out.println("第一行和为:"+s3+"\t其平均数为:"+h3);} } 手打不易,望采纳。
棣栭〉
<涓婁竴椤
5
6
7
8
10
11
12
9
13
14
涓嬩竴椤
灏鹃〉
其他人还搜