- Install node.js https://nodejs.org/en/
- File extensions for Javascript applications is
.js
// single line comment
/*
multi line comment
*/
// declare variable
var integer = 1352;
var float = 3.1415;
var txt = 'Hi Hi';
// if / else if / else statement
var i = 10;
if (i === 0) {
} else if (i === 1) {
} else {
}
// for loop
for (var x=0; x<10; x++) {
}
// while loop
var y = 0;
while (y < 10) {
y++;
}
// do while loop
var z = 0;
do {
z++;
} while (z < 10);
// function declaration
function add(num1, num2) {
return num1 + num2;
}
var sum = add(5, 7);
sample.js
function drawPyramid(height) {
for (var i=0; i<height; i++) {
var row = '';
for (var s=0; s<height; s++) {
row += ' ';
}
var k = 0;
while () {
}
console.log(row);
}
}
drawPyramid(5);
drawPyramid(10);
bash$ nano sample.js
bash$ node sample.js
- Install
gcc
ordev-c++
http://www.bloodshed.net/devcpp.html - File extension for C programs is
.c
and for C++ is.cpp
. Both use.h
for header files
// single line comment
/*
multi line comment
*/
// declare variable
char a = 'a';
short b = 6;
// 16-bit integer
int c = 3446;
signed int d = -475;
unsigned int e = 973;
// 32-bit integer
long f = 243578;
signed long g =
unsigned long h =
// 64-bit integer
long long i =
signed long long j =
unsigned long long k =
// float (IEEE 754 single-precision binary floating-point format)
float l = 3.1415
// double (IEEE 754 double-precision binary floating-point format)
float m = 2.6245762346;
// character string
char n = "Hello World!";
// if / else if / else statement
int i = 10;
if (i === 0) {
} else if (i === 1) {
} else {
}
// for loop
for (int x=0; x<10; x++) {
}
// while loop
int y = 0;
while (y < 10) {
y++;
}
// do while loop
int z = 0;
do {
z++;
} while (z < 10);
// function declaration
int add(int num1, int num2) {
return num1 + num2;
}
int sum = add(5, 7);
fib.c
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
bash$ nano fib.c
bash$ gcc fib.c -o fib
bash$ ./fib
- Install
jdk
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html - File extension for Java programs is
.java
// single line comment
/*
multi line comment
*/
// declare variable
char a = 'a';
short b = 6;
// 16-bit integer
int c = 3446;
signed int d = -475;
unsigned int e = 973;
// 32-bit integer
long f = 243578;
signed long g =
unsigned long h =
// 64-bit integer
long long i =
signed long long j =
unsigned long long k =
// float (IEEE 754 single-precision binary floating-point format)
float l = 3.1415
// double (IEEE 754 double-precision binary floating-point format)
float m = 2.6245762346;
// character string
String str = "abc";
// if / else if / else statement
int i = 10;
if (i === 0) {
} else if (i === 1) {
} else {
}
// for loop
for (int x=0; x<10; x++) {
}
// while loop
int y = 0;
while (y < 10) {
y++;
}
// do while loop
int z = 0;
do {
z++;
} while (z < 10);
// function declaration
int add(int num1, int num2) {
return num1 + num2;
}
int sum = add(5, 7);
PrimeNumber.java
class PrimeNumber {
// Checks whether an int is prime or not.
static boolean isPrime(int n) {
//check if n is a multiple of 2
if (n%2 == 0) {
return false;
}
//if not, then just check the odds
for(int i = 3; i*i <= n; i += 2) {
if (n%i == 0) {
return false;
}
}
return true;
}
// Main function
public static void main(String[] args) {
if (isPrime(16) == true) {
System.out.println("Is Prime Number");
} else {
System.out.println("Is NOT Prime Number");
}
}
}
bash$ javac PrimeNumber.java
bash$ java PrimeNumber
- Install ruby https://www.ruby-lang.org/en/documentation/installation/
- File extensions for Javascript applications is
.rb
# This is a single line comment.
=begin
This is a multiline comment and con spwan as many lines as you
like. But =begin and =end should come in the first line only.
=end
// declare variable
var integer = 1352;
var float = 3.1415;
var txt = 'Hi Hi';
# if / else if / else statement
x=1
if x > 2
puts "x is greater than 2"
elsif x <= 2 and x!=0
puts "x is 1"
else
puts "I can't guess the number"
end
# until statement
x=1
unless x>2
puts "x is less than 2"
else
puts "x is greater than 2"
end
# for statement
for i in 0..5
puts "Value of local variable is #{i}"
end
(0..5).each do |i|
puts "Value of local variable is #{i}"
end
# while loop
# the [do] is optional
$i = 0
$num = 5
while $i < $num do
puts("Inside the loop i = #$i" )
$i +=1
end
# while modifier
$i = 0
$num = 5
begin
puts("Inside the loop i = #$i" )
$i +=1
end while $i < $num
# until statement
$i = 0
$num = 5
until $i > $num do
puts("Inside the loop i = #$i" )
$i +=1;
end
# until modifier
$i = 0
$num = 5
begin
puts("Inside the loop i = #$i" )
$i +=1;
end until $i > $num
# method declaration
def test(a1="Ruby", a2="Perl")
puts "The programming language is #{a1}"
puts "The programming language is #{a2}"
end
test "C", "C++"
test
mulTable.rb
x = (1..12)
y = (1..12)
print ' '
x.each {|i| print "%-3d " % i}
print "\n "
x.each {|i| print '---- '}
print "\n"
y.each do |j|
print "%-3d| " % j
x.each {|i| print "%-3d " % (i*j)}
print "\n"
end
bash$ nano mulTable.rb
bash$ ruby mulTable.rb