Ask Question

Write a program that takes 10 integers as input. The program places the even integers into an array called evenList, the odd integers into an array called oddList, and the negative integers into an array called negativeList. The program displays the contents of the three arrays after all the integers have been entered

+1
Answers (1)
  1. 29 May, 03:02
    0
    import java. util. Scanner;

    public class Main{

    public static void main (String [] args) {

    Scanner integers = new Scanner (System. in);

    int a, countNegative = 0, countOdd = 0, countEven = 0;

    int []arr = new int[10];

    System. out. println ("Enter 10 integers");

    for (a = 0; a < arr. length; a++) {

    arr[a] = integers. nextInt ();

    if (arr[a] < 0)

    countNegative++;

    if (arr[a] % 2 = = 0)

    countEven++;

    if (arr[a] % 2 = = 1)

    countOdd++;

    }

    int[] oddList = new int[countOdd];

    int[] evenList = new int[countEven];

    int[] negativeList = new int[countNegative];

    int o, e, n, o1, e1, n1, i;

    for (o = 0; o < arr. length; o++) {

    if (arr[o] % 2 = = 1) {

    for (o1 = 0; o1 < countOdd-1; o1++) {

    oddList[o1] = arr[o];

    }

    }

    else if (arr[0] % 2 = = 0) {

    for (e1 = 0; e1 < countEven-1; e1++) {

    evenList[e1] = arr[o];

    }

    }

    else{

    for (n1 = 0; n1 < countNegative-1; n1++) {

    negativeList[n1] = arr[o];

    }

    }

    }

    for (i = 0; i < countOdd-1; i++) {

    System. out. println (oddList[i]);

    }

    for (i = 0; i < countNegative-1; i++) {

    System. out. println (negativeList[i]);

    }

    for (i = 0; i < countEven-1; i++) {

    System. out. println (evenList[i]);

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that takes 10 integers as input. The program places the even integers into an array called evenList, the odd integers into ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers