COMPARE JAVA, PHYTON, C++ AND RUBY WITH SOME SIMPLE EXAMPLES OF CODES FOR SAME PROBLEMS IN ALL OF THOSE LANGUAGES. (Program to check Even or Odd number) AND EXPLAIN DIFFERENCES IN THAT EXAMPLES FOR EVERY LANGUAGE, COMPARED TO OTHER LANGUAGE.
COMPARE JAVA, PHYTON, C++ AND RUBY WITH SOME SIMPLE EXAMPLES OF CODES FOR SAME PROBLEMS IN ALL OF THOSE LANGUAGES. (
For java
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int i;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number you want to check:");
i = s.nextInt();
if(i % 2 == 0)
{
System.out.println("The given number "+i+" is Even ");
}
else
{
System.out.println("The given number "+i+" is Odd ");
}
}
}
For python
n = int(input("Enter a number: "))
if (n % 2) == 0:
print("{0} is Even number".format(n))
else:
print("{0} is Odd number".format(n))
For c++
#include<iostream>
using namespace std;
int main()
{
int num, rem;
cout << "Enter the number : ";
cin >> num;
rem = num % 2;
if (rem == 0)
cout << num << " is an even integer " << endl;
else
cout << num << " is an odd integer " << endl;
return 0;
}
For ruby
# it is used for the initialization of the values
n1 = 18
n2 = 21
n3 = 28
n4 = 13
# for printing the integer value and the remainder
puts n1.even?
puts n2.even?
puts n3.even?
puts n4.even?
Step by step
Solved in 2 steps with 4 images