java - Using For-loops to get integers from user, then printing the even numbers -
this have far:
import java.util.scanner; public class evenarray {//begin class public static void main(string[]args) {//begin main method java.util.scanner input = new java.util.scanner(system.in); system.out.println(); system.out.println("please enter number of intergers want put array."); int numbers = input.nextint(); int[] arrayint = new int[numbers]; int = 0; system.out.println("please enter numbers enter array."); (i =1; < arrayint.length; i++){ arrayint[i] = input.nextint(); } int evennumber = 0; ( = 0; < arrayint.length; i++){ if(arrayint[i] % 2 == 0){ evennumber++; system.out.println("the numbers " + evennumber); } } } }
it compiles fine, prints:
dhh005@cs:~$ java evenarray
please enter number of intergers want put array. 6 please enter numbers enter array. 10 -7 3 42 -20 numbers 1 numbers 2 numbers 3 numbers 4
i cant figure out why isn't showing actual numbers. appreciated.
replace
system.out.println("the numbers " + evennumber);
with
system.out.println("the numbers " + arrayint[i]);
and can remove evennumber
variable altogether.
Comments
Post a Comment