Views: 206
Following program shows you how to take a number as input and tells its even or odd number.
This program divides input by 2, If remainder is zero it prints even otherwise it prints odd
import java.util.Scanner;
public class BasicMath10 {
public static void main(String[] args) {
System.out.println("Please enter a number:");
Scanner in = new Scanner(System.in);
int i = in.nextInt();
if (i % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
}
}
Output:
Example1:
Please enter a number:
4
even
Example2:
Please enter a number:
-5
odd
On By
Navya
Top Tutorials
492.5K
31.9K
21.7K
18.7K
18.6K
6.7K
6.6K
4.9K
3.3K
3.1K
Top Questions
18.6K
14.5K
8.3K
6.5K
6.1K
5.7K
4.8K
4.8K
4.3K
3.9K
Top Articles
1.9K
1.6K
944
Top Blogs
792
778
52
Top News
750
683
669
397
381
381