0

Does not work.

what do you mean by this? is there an error or you can't get the desired output?
could you post those errors or output.

hmm.. well I tried the program and did what I suggested and I got it to work...

0

Can you post your code? I really do not understand why I do not get the desired output.

0

Can you post your code?

That sounds like I'd be spoon feeding you so sorry but I'll pass

I really do not understand why I do not get the desired output.

Print the values of odd[count] and even[count] in the while loop and you'd see that eventually they'd get the values of:
odd[count] with {1,2,3,4,5,6,7,8,9} and
even[count] with {2,3,4,5,6,7,8,9,10}
so simple iteration won't work

at the odd numbers it should remain as the value of i
and the same at even numbers i+1

then use

sum[count] = odd[count] + even[count];

then after count+=1; , iterate using i+=2;

that should give the right values for the odd and even numbers at your code

Edited by zeroliken: n/a

0

Here is my code:

public class ArrayTest
{
public static void main(String[] args)
{
arrayCombiner();
} // end main
public static void arrayCombiner()
{
int[] odd=new int[10];
int[] even=new int[10];
int[] sum=new int[10];
int count=0;
int i=1;
while(count<10)
{
odd[count]=i;
even[count]=i+1;
sum[count]=odd[count]+even[count];
count+=1;
i+=2;
for(int sumCount:sum)
{
System.out.printf("%d ",sumCount);
}
 }
  } // end arrayCombiner
   } // end class ArrayTest

I do not get the desired output.

0

Still cannot get it to work.

public class ArrayTest
{
public static void main(String[] args)
{
arrayCombiner();
} // end main
public static void arrayCombiner()
{
int[] odd=new int[10];
int[] even=new int[10];
int[] sum=new int[10];
int count=0;
int i=1;
while(count<10)
{
odd[count]=i;
even[count]=i+1;
sum[count]=odd[count]+even[count];
count+=1;
i+=2;
}
for(int sumCount:sum)
{
System.out.printf("%d ",sumCount);
}
 }
  }
   } // end arrayCombiner
    } // end class ArrayTest
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.