java用程序实现求两个数组中相同元素的个数 15
int[]oneArray={30,1,9,20,11,15,41,25,52,8};int[]twoArray={15,7,1,30,22,13,40,11,8,50}...
int[] oneArray = {30, 1, 9, 20, 11, 15, 41,25,52,8};
int[] twoArray = {15, 7, 1, 30, 22, 13, 40,11,8, 50} 展开
int[] twoArray = {15, 7, 1, 30, 22, 13, 40,11,8, 50} 展开
1个回答
展开全部
public class T
{
public static void main(String[] args)
{
int[] oneArray = {30, 1, 9, 20, 11, 15, 41,25,52,8};
int[] twoArray = {15, 7, 1, 30, 22, 13, 40,11,8,50};
int count=0;
boolean find;
for(int i=0;i<oneArray.length;i++)
{
find=false;
for(int j=0;j<twoArray.length;j++)
{
if(oneArray[i]==twoArray[j])
{
if(!find)
{
count++;
find=true;
}
twoArray[j]=-1;
}
}
}
System.out.println("数组oneArray与数组twoArray共有"+count+"个相同的元素!");
}
}
{
public static void main(String[] args)
{
int[] oneArray = {30, 1, 9, 20, 11, 15, 41,25,52,8};
int[] twoArray = {15, 7, 1, 30, 22, 13, 40,11,8,50};
int count=0;
boolean find;
for(int i=0;i<oneArray.length;i++)
{
find=false;
for(int j=0;j<twoArray.length;j++)
{
if(oneArray[i]==twoArray[j])
{
if(!find)
{
count++;
find=true;
}
twoArray[j]=-1;
}
}
}
System.out.println("数组oneArray与数组twoArray共有"+count+"个相同的元素!");
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询