我想问一下,比如:我现在有一个数组a int [] a = new int[]{10,8,9,7,5,1,2,3};
我想通过两个数组b和c,去分离这个数组a,
将比4大的值放入数组b中,
将比4小的值放入数组c中,
其中b只能是存在比4大的值,
其中c只能是存在比4小的值!!!!!
b或c中不能再有其他的数值出现!!!!!
我想看看大家的思想是怎么样的????
希望得到大家的帮助!!!!
...全文
43811打赏收藏
一个数组的问题
我想问一下,比如:我现在有一个数组a int [] a = new int[]{10,8,9,7,5,1,2,3}; 我想通过两个数组b和c,去分离这个数组a, 将比4大的值放入数组b中, 将比4小的值放入数组c中, 其中b只能是存在比4大的值, 其中c只能是存在比4小的值!!!!! b或c中不能再有其他的数值出现!!!!! 我想看看大家的思想是怎么样的???? 希望得到大家的帮助!!!!
行了。通过了。结贴吧。
import java.util.*;
public class testarray
{
public static void main(String[]args)
{
int [] a = new int[]{10,8,9,7,5,1,2,3};
ArrayList c = new ArrayList();
ArrayList b = new ArrayList();
for(int i = 0;i< a.length;i++)
{
if (a[i] >=4)
c.add(a[i]);
else
b.add(a[i]);
}
Integer[]b1 = new Integer[b.size()];
Integer []c1 = new Integer[c.size()];
c.toArray(c1);
b.toArray(b1);
for(int i = 0;i<b1.length;i++)
System.out.println(b1[i]);
for(int i = 0;i<c1.length;i++)
System.out.println(c1[i]);