JAVA编程问题求助 编写程序,把一个数组中的元素倒过来。例如原数组为1,2,3,4,5。则倒排 10
1个回答
展开全部
<pre t="code" l="java">
import java.util.Arrays;
public class YuGiOh
{
private static void makeLove ( int[] a )
{
String tmp = " " + Arrays.toString (a).replaceAll ("[\\[\\]]", ",").replaceAll ("\\s", "").replaceAll ("(?<=\\d+)\\,(?=\\d+)", ",,") + " ";
String result = " ";
for ( int i = 0; i < a.length; i++ )
{
int ai = a[i];
if (( tmp.split ("\\," + ai + "\\,").length - 1 ) % 2 != 0)
{
if (result.indexOf (" " + ai + " ") == -1)
{
result += ai + " ";
}
}
}
System.out.println (result.trim ());
}
public static void main ( String[] args )
{
int[] a = { 1, 1, 1, 2, 4, 3, 3 };
makeLove (a);
}
}
import java.util.Arrays;
public class YuGiOh
{
private static void makeLove ( int[] a )
{
String tmp = " " + Arrays.toString (a).replaceAll ("[\\[\\]]", ",").replaceAll ("\\s", "").replaceAll ("(?<=\\d+)\\,(?=\\d+)", ",,") + " ";
String result = " ";
for ( int i = 0; i < a.length; i++ )
{
int ai = a[i];
if (( tmp.split ("\\," + ai + "\\,").length - 1 ) % 2 != 0)
{
if (result.indexOf (" " + ai + " ") == -1)
{
result += ai + " ";
}
}
}
System.out.println (result.trim ());
}
public static void main ( String[] args )
{
int[] a = { 1, 1, 1, 2, 4, 3, 3 };
makeLove (a);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询