Results 1 to 3 of 3
Thread: Array Odds and Evens
- 11-21-2012, 09:32 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
Array Odds and Evens
Create an array of 10 integers. Write a program print all the odd numbers then, on a new line, print out the number of even numbers.
Steps
I'm a newb, and getting stuck on how to properly print out the odds and count the evens. So far I'm getting it to print the odds in a list, but then it's just printing everything else after?
public class ArrayProblem{
public static void main(String[] args){
int [] newArray = {9,45,11,2,4,6,8,10,12,14};
System.out.println("The odd numbers are :");
for(int i=0;i<newArray.length;i++){
if(newArray[i]/2 != 0){
System.out.println(newArray[i]);
}
else{
}
}
}
}
- 11-22-2012, 12:13 AM #2
Re: Array Odds and Evens
Clearly you need to add some code to the else part. The if handles the odd numbers. So what should the else do?
- 11-22-2012, 04:08 AM #3
Re: Array Odds and Evens
Guide For New Members
BB Code List - Java Programming Forum
Also, learn how to use the remainder (aka modulo or modulus) operator: Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Reading a text file into an Array and spliting the content into another Array
By jtothemax in forum New To JavaReplies: 15Last Post: 05-14-2012, 12:42 PM -
Evens odds & likes 7
By Martyn in forum New To JavaReplies: 6Last Post: 11-15-2011, 10:36 AM -
Display Array on another class after extracting from txt file and into array problem
By jonathan920 in forum NetBeansReplies: 0Last Post: 05-12-2011, 07:04 PM -
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks