create two arrays in java A and B of size 5 and C of size 10.Accept numbers in two arrays A and B.fill the array in such a way that all odd positions occupy the numbers present in array and all even positions occupy the numbers present in array B.
Answers
Answered by
1
import java.io.DataInputStream;
import java.io.IOException;
public class ques1
{
public static void arr() throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int n[] = new int[10];
for(int i = 0;i<10;i++)
{
System.out.print ("Enter a number : ");
n[i] = Integer.parseInt ( in.readLine() );
}
int evenSum = 0,oddSum = 0;
for(int i = 0;i<10;i++)
{
if(i%2 = = 0)
oddSum = oddSum+n[i];
else
evenSum = evenSum+n[i];
}
System.out.println ("Sum of ODD Location : " + oddSum);
System.out.println ("Sum of EVEN Location : " + evenSum);
}
}
Similar questions