打印出随机数组 [英] Printing out a Random Array

查看:60
本文介绍了打印出随机数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import java.util;


public class Compact

{

public static int [] randomArray(int n)

{

int [] a = new int [n];

for(int i = 0; i< a.length; i ++)

{

a [i] = Math.random();

}

返回a; < br $>
}


public static double [] printArray(double [] a)

{

for (int i = 0; i< a.length; i ++)

{

返回[i];

}

}


public static void main(String args [])

{

System.out.println( 测试打印+ printArray(a));

}

}



上面的代码,我想要做的是创建一个随机整数数组。数组的大小是20.我不知道如何调用数组...

import java.util;

public class Compact
{
public static int[] randomArray (int n)
{
int[] a = new int[n];
for (int i = 0; i < a.length; i++)
{
a[i] = Math.random();
}
return a;
}

public static double[] printArray (double[] a)
{
for (int i = 0; i<a.length; i++)
{
return a[i];
}
}

public static void main(String args[])
{
System.out.println("Test for printing " + printArray(a));
}
}


In the above code, what I am trying to do is create an array with random integers. The size of the array is 20. I don''t know how to call the array...

推荐答案

你有没有尝试编译它并阅读编译器的内容不得不说呢? btw,

你不能称之为阵列,你可能会喊''yoohoo''但是我确定它不会反应也不会

响应。数组有点愚蠢。


亲切的问候,


Jos
Have you tried to compile it and read what the compiler had to say about it? btw,
you can''t call an array, you might yell ''yoohoo'' at it but I''m sure it won''t react nor
respond. Arrays are kind of stupid.

kind regards,

Jos



您是否尝试过编译它并阅读编译器有关它的内容? btw,

你不能称之为阵列,你可能会喊''yoohoo''但是我确定它不会反应也不会

响应。数组有点愚蠢。


亲切的问候,


Jos
Have you tried to compile it and read what the compiler had to say about it? btw,
you can''t call an array, you might yell ''yoohoo'' at it but I''m sure it won''t react nor
respond. Arrays are kind of stupid.

kind regards,

Jos



import java.util;


public class Compact

{

public static void main(String [] args)

{

public static int [] randomArray(int n)

{

int [] a = new int [n ];

for(int i = 0; i< a.length; i ++)

{

a [i] = Math.random ();

}

System.out.println(a);

}

}

}


由于某些原因,这不起作用,它表示在randomArray方法中非法表达式开始。预期在倒数第二个括号中使用分号


import java.util;

public class Compact
{
public static void main(String[] args)
{
public static int[] randomArray (int n)
{
int[] a = new int[n];
for (int i = 0; i < a.length; i++)
{
a[i] = Math.random();
}
System.out.println (a);
}
}
}


this doesn''t work for some reason, it says illegal start of expression at the randomArray method. and a semicolon is expected at the second to last bracket


当您的语法偏离标记时,生成的编译器消息可能没有用,因为编译器非常困惑。就是这种情况。


你在方法main中嵌套方法randomArray的定义。换句话说,你写道:

When your syntax is way off the mark, the resulting compiler messages may not be helpful, because the compiler is so confused. That is the case, here.

You nested the defintion of method randomArray inside method main. In other words, you wrote:

展开 | 选择 | Wrap | 行号


这篇关于打印出随机数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆