Posts

Showing posts with the label Odd or Even

C++ Odd or Even

This is a great code example for determining if user input is a Odd or Even Number * Featured Code Example Created and submitted by  tooselfish  via Sololearn. C++ Odd or Even #include <iostream> int main() {     int a = 0;                 // input one whole integer     std::cin >> a;                 // for input failure     if( std::cin.fail() ){         std::cerr << "Wrong input!\n";         return 1;     }          std::cout << "Your number is: " << a << std::endl;               // test odd or not     if (a %2 != 0){         std::cout << "Your number is odd!" << std::endl;     } else {   ...

Java Odd or Even

Code Example to determine if a number entered is odd or even import java.util.Scanner; class OddOrEven { public static void main(String args[]) { int num; System.out.println("Enter an Integer number:"); Scanner input = new Scanner(System.in);  num = input.nextInt(); if ( num % 2 == 0 ) System.out.println("The number is even");   else System.out.println("The number is odd"); } } Click here to see this code run Java Fun Fact Java was called Oak at the beginning The original name for Java was Oak. Java legend has it that a big oak tree that grew outside the developer James Gosling’s window.  More Free Code Examples: Java Current Time and Date Program JavaScript Substitution Cipher Angular Click Counter