Even and odd functions in java

View Answers

May 17, 2012 at 5:56 PM

Example:

import java.util.*; public class EvenOddFunction { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; System.out.println("Input any number to check even or odd:"); number = input.nextInt(); evenMethod( number); oddMethod(number); } public static void evenMethod(int n) { if (n % 2 == 0){ System.out.println("Your number " + n + " is even"); } } public static void oddMethod(int n) { if (n % 2 != 0) { System.out.println("Your number " + n + " is odd"); } } }

**Description :** Number which is divisible by 2 is called even numbers and which is not divisible by 2 is called odd numbers.
Here we have two separate functions for checking either number is even or odd. We are passing number as
argument in methods.

Ads

Related Tutorials/Questions & Answers:

Even and odd functions in java Even and odd functions in java ... have two separate functions for checking either number is even or odd. We...); int number; System.out.println("Input any number to check even

odd and even how can i make a program of even and odd using case...{ System.out.println(); System.out.println("1 Display Even"); System.out.println("2 Display Odd"); System.out.println("3 Exit"); System.out.print("Choose

Advertisements

PRIME AND EVEN AND ODD how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers

Check even or odd number. How to check given number is even or odd? Simple if it is devided by 2 it is even and if not if is Odd ...){ System.out.println("Number is Even"); } else

Odd Even Transposition Sort In Java ... In this example we are going to sort integer values of an array using odd even transposition sort. Odd even transposition sort is a parallel sorting algorithm. Odd Even

Calculate sum of even and odd numbers In this section, you will learn how to read the file that contains even and odd numbers and calculate their sum separately. To do this, first of all, we have found all the even and odd numbers from 1

JSTL - check odd/even number How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number

java code for print true if even and false if odd and print error if any float value with out using conditional and looping statement hi class Even{ public static void main(String[] arg){ int num=Integer.parseInt

Check whether highest number is even or odd In this section, you will learn... it is odd or even. For this, we have taken two integer variables num1 and num2... that if the highest number is totally divided by 2,then it is even, otherwise

EVEN NUMBERS i want program of even numbers?i want source code plz reply? Hi Friend, Try the following code: class EvenNumbers... counter = 0; System.out.println("Even Numbers are:" ); for (int i

even more circles Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user

Inverse of trigonometric functions in java. How to get inverse of trigonometric functions in java? public class InverseTrigno... Trigonometric functions are sin, cos and tan. Inverse of these functions

Check Even-Odd:-Example ... reads a integer value and check weather number is Odd or Even. In this example you will learn how to determine the Even or Odd for the given number entered

NoSuchMethodException even if method defined Hi I am loading a class (Student) dynamically from a jar (samplejar.jar) file using URLClassLoader. Next thing when I want to access method or constructor of the previously loaded

odd numbers with loop get the odd numbers till 100 with for,while loop Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i

A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... the console. Now here is the simple example which will help you to find the sum of odd

Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type... leaving 0 remainder, then it should be an even number and stored in the file. We

java memory allocation for member variables and member functions ... an object q of test class then when shall the memory be allotted for function fun() and its variables ?? 4>When does java set default values of variables declared

How to Use Java Functions In EL To use a Java Functions in EL we.... The java class: In this class the functions declared must be public

retaining save dialog box even after clicking save button I am... get it back??(even if i cal save dialog box again it would open again from... with source code to solve the problem and specify the technology used Java/Jsp

how to make session valid even browser has closed Hi, I have doubt that session will close when we close the web browser. My doubt is, even when I close the browser my session should not close or delete. How can I do

WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java

Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java Q, 12 WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java

WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java

WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java WAP to calculate addition of two distances in feets and inches using objects as functions arguments in java

What is functions? Hi, Please tell me about PHP functions? Thanks in advance. About Functions: Functions in PHP is block of code... functions and use it multiple times. In PHP there is many pre-defined functions