返回信息流public static void main(String[] args)
{
System.out.println( ispermutation({0,1,1,4}, "test array") );
}
static boolean ispermutation(int[] A, String info)
这种情况会报错:
但是换成
public static void main(String[] args)
{
int[] B ={0,1,1,4};
System.out.println( ispermutation(B,"test array") );
}
static boolean ispermutation(int[] A, String info)
却是对的
为什么?
这是一条镜像帖。来源:北邮人论坛 / java / #12631同步于 2009/12/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
[求助]菜鸟请教一个关于函数调用时数组传值的问题
appleman591
2009/12/10镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
在JAVA中数组也是一个对象,可以使用下面的方法传参:
ispermutation(new int[]{0,1,1,4}, "test array") ;
【 在 appleman591 的大作中提到: 】
: public static void main(String[] args)
: {
: System.out.println( ispermutation({0,1,1,4}, "test array") );
: ...................
题目的要求是用 ispermutation({0,1,1,4}, "test array") 调用,哎!都不知道咋办了
static boolean ispermutation (int[] A, String info)
that returns true if the integers in the array A represent a permutation of the numbers
0,1, . . . ,n−1, where n is the length of A (meaning each number appears exactly once) and
false otherwise.
A “wrong” entry A[i] is either negative or greater than n−1, or a repetition of a number
that has appeared earlier. All such wrong entries should be printed, preceded by the info
string. For example, the call ispermutation({0,1,1,4}, "test array") should produce
the output
wrong entry 1 in test array at position 2
wrong entry 4 in test array at position 3
since the array entries at positions 2 and 3 are incorrect (the first a repetition, the second
out of range), and its return value should be false.
【 在 vcpp 的大作中提到: 】
: 在JAVA中数组也是一个对象,可以使用下面的方法传参:
: ispermutation(new int[]{0,1,1,4}, "test array") ;
Lz想多了,我想题意是让你接受一个数组作为参数,文中只是为了举例说明才那样写的。
要不然,随便输入一个数组,怎么构造成像{x,x,x..}这样的形式的参数啊。
嗯,明白了,THX
【 在 vcpp 的大作中提到: 】
: Lz想多了,我想题意是让你接受一个数组作为参数,文中只是为了举例说明才那样写的。
: 要不然,随便输入一个数组,怎么构造成像{x,x,x..}这样的形式的参数啊。
【 在 appleman591 的大作中提到: 】
: public static void main(String[] args)
: {
: System.out.println( ispermutation({0,1,1,4}, "test array") );
: ...................
代码错了