My psuedo code of the logic is
1. loop through given array
2. find occurence of zero as long as not a last elemet
3. find the biggest odd after occurence of zero
4 replace i th element with biggest odd.
5 return array

import java.util.Scanner;public class ZeroMax { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number of elements: "); int n = sc.nextInt(); int[] a = new int[n]; int i, smallEven=0, bigOdd=0, countOdd=0, countEven=0; for(i=0; i<n; i++){ System.out.print("Enter element "+(i+1)); a[i]=sc.nextInt(); if(a[i]%2 == 1){ if(countOdd>0 && a[i]>bigOdd) bigOdd=a[i]; else if(countOdd==0) bigOdd=a[i]; countOdd++; } else{ if(countEven>0 && a[i]<smallEven) smallEven=a[i]; else if(countEven==0)smallEven=a[i]; countEven++; } } System.out.println("The smallest even number is " + smallEven); System.out.println("The largest odd number is " + bigOdd); }}

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

There's nothing particularly wrong with your pseudo-code it is just point 3 that needs to be expanded, ie. Now you know the i-th element is zero, HOW do you find the biggest odd number after the i-th element.

Hint: to find the max you need to look at each element from the one after the i-th element to the end of the array, ie. you need a second loop. This will be within the first, main loop.

each zero value in the array is replaced by the largest odd value to the right

If the first loop finds a zero, the second loop looks to the right to find the largest odd number to replace the zero.
If you find a zero with the second loop, you ignore it because you are only looking for odd numbers.
If there are more zeros in the array, the first loop will find them eventually.

i passed all tests with one 0. How pass tests with more than one 0?

import java.util.Arrays;import java.util.Scanner;/*There's nothing particularly wrong with your pseudo-code it is * just point 3 that needs to be expanded, ie. Now you know the * i-th element is zero, HOW do you find the biggest odd number * after the i-th element.Hint: to find the max you need to look at each element from the one after the i-th element to the end of the array, ie. you need a second loop. This will be within the first, main loop.*/public class ZeroMax2 { public static void main(String[] args) { int[] ar = { 0, 5, 0, 3 }; System.out.println("value is" + Arrays.toString(zeroMax(ar))); /* * Return a version of the given array where each zero value in the * array is replaced by the largest odd value to the right of the zero * in the array. If there is no odd value to the right of the zero, * leave the zero as a zero. * * zeroMax([0, 5, 0, 3]) → [5, 5, 3, 3] zeroMax([0, 4, 0, 3]) → [3, 4, * 3, 3] zeroMax([0, 1, 0]) → [1, 1, 0] * * Hint: to find the max you need to look at each element from the one * after the i-th element to the end of the array, ie. you need a second * loop. This will be within the first, main loop. */ } public static int[] zeroMax(int[] nums) { for (int i = 0; i < nums.length; i++) { if (nums[i] == 0) { if (nums[i] == 0) { int largest=nums[i]; for (int j = i; j < nums.length; j++) { if(nums[j]>largest){ largest=nums[j]; } if(largest>0){ nums[i]=largest; } } } } } return nums; }}

You can do the challenge much more efficiently (with one loop) by working right to left, keeping track of the largest odd integer, and replacing 0's as you go.

largest has no meaning until you find an odd integer.
But you can give it a clever initial value that allows it to work as a flag and simplify your program.

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

This article describes and provides a custom-made tool I wrote to give businesses a means of identifying commercial music content, without having to expend too much effort. Business recordings are easily identified from possibly illegal music files …

With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…