lundi 5 décembre 2016

Getting Odd numbers from Array

I've been working on this program and am currently stuck. The HW prompt is to prompt a user to input numbers, save it as an array, find the number of odd numbers & the percentages then display those values back to the user.

Currently I am trying to write to part of the code that finds the percentage of the odd numbers in the array but the return isn't displaying and i just cant figure it out. Any ideas? Thank you!

import java.util.*; // import java course for Scanner class
public class Integers {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.println("Please input a series of numbers");
        int inputs = Integer.parseInt(console.next());
        int[] arraysize = new int[inputs];
        Oddvalues(arraysize);
        }

    public static int Oddvalues (int[] size) {
        int countOdd = 0;
        for (int i=1; i < size.length; i++){
            if(size[i]%2 != 0){
             i++;
            }

        }
        return countOdd;    
        }

}

Aucun commentaire:

Enregistrer un commentaire