I am missing a formula to make it odd; This same loop should determine how many integers in the array are odd numbers. After this loop ends, use this figure to declare a new array of integers named odds. Process the array again in the method, but this time with a foreach loop, and add the odd integers to the odds array. Return the odds array back to main. In main, report the size of the array and sort it ascending. Finally use a while loop to print the odd integers all on one line separated by spaces. I am also tring to make it 4 rows and 8 columns. This is what the professor wants: Write a program that creates a 32-element array of random integers all from 1 to 100, inclusive. Then execute a custom method with the array as its only argument. The method should begin by using a loop to print the array elements in 4 rows and 8 columns, with all columns being five characters wide. Duplicates are okay. This same loop should determine how many integers in the array are odd numbers. After this loop ends, use this figure to declare a new array of integers named odds. Process the array again in the method, but this time with a foreach loop, and add the odd integers to the odds array. Return the odds array back to main. In main, report the size of the array and sort it ascending. Finally use a while loop to print the odd integers all on one line separated by spaces. DOES NOT USE TEMPERATURE This is what I have so far: public static int[] oddNumbers(int[] r) { int random = 0; for (int i = 0; i < r.length; i++) { if (i == 0 || i %5 != 0) { System.out.print(r[i] + " ");} else { System.out.println(); System.out.print(r[i] + " "); } if (r[i] < 32) { random ++; } } int[] f_array = new int[random]; int ran = 0; for (int i : r) { if (i < 32) { f_array[ran] = i; ran ++; } } return f_array; } public static void main(String[] args) { int[] arr = new int[32]; for (int i = 0; i < arr.length; i++) { arr[i] = (int) (Math.random() * 100 - 10) + 10; } int[] res = oddNumbers(arr); Arrays.sort(res); System.out.println("\nPrinting the Sorted values.\n"); for (int i = 0; i < res.length; i++) { if (i == res.length - 1) { System.out.print(res[i]);} else { System.out.print(res[i] + " "); } } System.out.print("\n"); } }
I am missing a formula to make it odd; This same loop should determine how many integers in the array are odd numbers. After this loop ends, use this figure to declare a new array of integers named odds. Process the array again in the method, but this time with a foreach loop, and add the odd integers to the odds array. Return the odds array back to main. In main, report the size of the array and sort it ascending. Finally use a while loop to print the odd integers all on one line separated by spaces.
I am also tring to make it 4 rows and 8 columns.
This is what the professor wants: Write a program that creates a 32-element array of random integers all from 1 to 100, inclusive. Then execute a custom method with the array as its only argument. The method should begin by using a loop to print the array elements in 4 rows and 8 columns, with all columns being five characters wide. Duplicates are okay. This same loop should determine how many integers in the array are odd numbers. After this loop ends, use this figure to declare a new array of integers named odds. Process the array again in the method, but this time with a foreach loop, and add the odd integers to the odds array. Return the odds array back to main. In main, report the size of the array and sort it ascending. Finally use a while loop to print the odd integers all on one line separated by spaces.
DOES NOT USE TEMPERATURE
This is what I have so far:
public static int[] oddNumbers(int[] r) {
int random = 0;
for (int i = 0; i < r.length; i++) {
if (i == 0 || i %5 != 0) {
System.out.print(r[i] + " ");}
else {
System.out.println();
System.out.print(r[i] + " ");
}
if (r[i] < 32) {
random ++;
}
}
int[] f_array = new int[random];
int ran = 0;
for (int i : r) {
if (i < 32) {
f_array[ran] = i;
ran ++;
}
}
return f_array;
}
public static void main(String[] args) {
int[] arr = new int[32];
for (int i = 0; i < arr.length; i++) {
arr[i] = (int) (Math.random() * 100 - 10) + 10;
}
int[] res = oddNumbers(arr);
Arrays.sort(res);
System.out.println("\nPrinting the Sorted values.\n");
for (int i = 0; i < res.length; i++) {
if (i == res.length - 1) {
System.out.print(res[i]);}
else {
System.out.print(res[i] + " ");
}
}
System.out.print("\n");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images