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

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

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

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

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

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

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

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

) 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

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

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

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

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

Functions and Methods Write a Java program to input the sides of a triangle. Pass the sides to a function decide(int x,int y,int z) which checks and prints whether the triangle is equilateral,isosceles or scalene.

Java reverse string without using inbuilt functions In this tutorial, you will learn how to reverse string without using any inbuilt functions. Here, we have created a method to reverse the string and returns a new string with reverse

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

2. Static Functions 3. Instance Variable Static Variables Static.... For more information, visit the following links: Java Static Variables Java Instance Variables Java Static Method Static Variables Static variables

Functions and Methods (1) Write a program in java to input 10... in java to input day number. Use a function daysofweek(int dysno) to accept... to print the corresponding day of the week. (3) Write a Java program to input

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

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' 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' Hi, My Python... 'even-tester' How to remove the ModuleNotFoundError: No module named 'even-tester' error? Thanks Hi, In your python environment

functions strstr() and stristr(). What is the functionality of the functions strstr() and stristr

the functions unlink and unset What is the difference between the functions unlink and unset

JavaScript array of functions In this Tutorial we want to describe you a code that help in understanding a JavaScript array of functions. For this we are using Java Script