# Even and odd functions in java

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  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
Check even or odd number.
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
Advertisements
Odd Even Transposition Sort In Java
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
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
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 Even-Odd:-Example
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
odd numbers with loop
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
ModuleNotFoundError: No module named 'odd'
ModuleNotFoundError: No module named 'odd'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odd' How to remove the ModuleNotFoundError: No module named 'odd' error
A program to find the sum of odd number
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
ModuleNotFoundError: No module named 'odd-bunch'
ModuleNotFoundError: No module named 'odd-bunch'  Hi, My Python... 'odd-bunch' How to remove the ModuleNotFoundError: No module named 'odd... have to install padas library. You can install odd-bunch python with following
java program13
java program13  Write a java propgram to find the list even and odd... even=" ",odd=" "; Scanner input=new Scanner(System.in...++){ if(i%2==0){ even+=i+" "; } else{ odd
java programming
) with a statement indicating whether it is even or not.. Output: Example Number 0 - Even Number 1 - Odd Number - 2 Even . . . Number 999 - Odd...java programming  Write a complete Java Program that correctly does
ModuleNotFoundError: No module named 'even_detector'
ModuleNotFoundError: No module named 'even_detector'  Hi, My... 'even_detector' How to remove the ModuleNotFoundError: No module named 'even_detector' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'even_detector'
ModuleNotFoundError: No module named 'even_detector'  Hi, My... 'even_detector' How to remove the ModuleNotFoundError: No module named 'even_detector' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'even-tester'
ModuleNotFoundError: No module named 'even-tester'  Hi, My Python... 'even-tester' How to remove the ModuleNotFoundError: No module named 'even-tester' error? Thanks   Hi, In your python environment
How to list even numbers between 1 and 100?
How to list even numbers between 1 and 100?  Hi, I Java to check if a number is even? How to list even numbers between 1 and 100? Thanks   Hi, If number is divisible by 2 then its even number. Suppose you have
java progaram - Java Beginners
and display the odd and even numbers of the list separately   Hi Friend, Try... void main(String[]args){ String even=""; String odd=""; for(int i=1;i<=50;i++){ if(i%2==0){ even+=i+" "; } else{ odd+=i
Inverse of trigonometric functions in java.
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
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
ModuleNotFoundError: No module named 'does-this-even-work-anymore'
ModuleNotFoundError: No module named 'does-this-even-work-anymore'  ...: No module named 'does-this-even-work-anymore' How to remove the ModuleNotFoundError: No module named 'does-this-even-work-anymore' error? Thanks
ModuleNotFoundError: No module named 'even-more-itertools'
ModuleNotFoundError: No module named 'even-more-itertools'  Hi, My... named 'even-more-itertools' How to remove the ModuleNotFoundError: No module named 'even-more-itertools' error? Thanks   Hi
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine
log4j is not logging even under src path
log4j is not logging even under src path  We are working with struts application and using log4j.properties file , it is placed under WEB-INF/classes and we have referenced log4j-1.2.8.jar in classpath file even after
Mysql Mod
Mysql Mod       Mysql Mod (a,b) is performed to return remainder  when b is divided by a. Incase you use MOD(a, 3) you get 1 for even numbers and 0 for odd numbers. If you use
Download all dependencies with yumdownloader, even if already installed?
Download all dependencies with yumdownloader, even if already installed?  Hi, I want to download all the dependencies with yumdownload even... for Download all dependencies with yumdownloader, even if already installed? Thanks
Java
Java  Write a program that repeatedly reads an integer from the console. If the integer is odd, outputs "Odd Day" if the integer is even (and not 0), outputs â??Even now". if the integer is 0. exits program
Display Hello even before main get executed??
Display Hello even before main get executed??  I have a class (main method) as follow.....As I know this can be done using static method, but Q is how? **class Hello{ public static void main(String[] args
Java Program
Java Program  I want the answer for this question. Question: Write a program to calculate and print the sum of odd numbers and the sum of even...(using for loop). Instructions: *You should surely use Functions in this question
java
java   How to find out whether a given input is a odd number or even number
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static
ModuleNotFoundError: No module named 'even-better-setuptools-git-version'
ModuleNotFoundError: No module named 'even-better-setuptools-git-version' ...: ModuleNotFoundError: No module named 'even-better-setuptools-git-version' How to remove the ModuleNotFoundError: No module named 'even-better-setuptools-git-version

Ads