this example explains three important topics of Java
1. read input from keyboard
2. if-else statement
3. calculate if the number is even or odd
import java.util.Scanner;
public class FindEvenOrOddNumber {
public static void main(String[] args) {
// main() function
Scanner keyboard = new Scanner(System.in);
// Scanner object to read input from keyboard
System.out.println("enter an integer");
int even_odd = keyboard.nextInt();
if(even_odd%2 == 0) //check if number is odd or even
System.out.println(even_odd + " is even number.");
else
System.out.println(even_odd + " is odd number.");
}
}
Watch video here
https://youtu.be/sX0XAROhuiQ
No comments:
Post a Comment