Java Programming help at HelpWithAssignment.com (Finding Even and Odd Numbers)

Published: 17th February 2011
Views: N/A
Ask About This Article Print Republish This Article
Java is one of the most popular Programming languages in use today in Application software and Web Applications. It is a general-purpose, concurrent, class based and object oriented language that is specifically designed to have implementation dependencies as possible.



Let us look at an example on finding whether a Number is Even or an Odd number.



public class FindEvenOrOddNumber {



public static void main(String[] args) {



//create an array of 10 numbers



int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};



for(int i=0; i < numbers.length; i++){



/*



* use modulus operator to check if the number is even or odd.



* If we divide any number by 2 and reminder is 0 then the number is



* even, otherwise it is odd.



*/



if(numbers[i]%2 == 0)



System.out.println(numbers[i] + " is even number.");



else



System.out.println(numbers[i] + " is odd number.");







}



}



}



Here in this example an array is being created and defined. Here "for(int i=0; i < numbers.length; i++){ " is meant to be the initialization and definition. For(int i=0; I < numbers.length; i++ means that the I cannot be zero and must be greater than the divisor in this case because as we move forward in the code we can see that the definition for the array says that if the number is divided by 2 and the remainder is 0 then the number is an even number. But, mathematically 0 is neither an odd nor an even number, so clearly this rule cannot be broken.



The array "create an array of 10 numbers" is being initiated with a loop "for(int i=0; i < numbers.length; i++){ /*" to calculations to be performed which completes the whole array and the outputs of whether the numbers are even or odd are returned.




At HelpWithAssignment.com we provide the best Java Assignment and Homework help. We also offer Online Tutoring in Java.



For more help on Java Programming help you can visit our website at http://www.helpwithassignment.com/programing-assignment-help. You can follow us on our blogs at http://helpwithassignment.wordpress.com/ and http://helpwithassignment.blogspot.com/


This article is free for republishing
Source: http://albertfrank.articlealley.com/java-programming-help-at-helpwithassignmentcom-finding-even-and-odd-numbers-2041055.html


Report this article Ask About This Article Print Republish This Article


Loading...
More to Explore
 


Ask a Professional Online Now
27 Experts are Online. Ask a Question, Get an Answer ASAP.
Type your question here...
Optional:
Select...