Thursday, 25 June 2015

Write a C# program to print the Prime numbers between 1 to 1000

using System;

class pro
{
    static void Main()
    {
        int[] prime = new int[1000];
        int i, j;
        for (i = 0; i < 1000; i++)
        {
            prime[i] = i + 1;
        }
        Console.WriteLine("Prime Number between 1 to 1000 \n");
        for (i = 0; i < 1000; i++)
        {
            for (j = 2; prime[i] > j; j++)
            {
                if (prime[i] % j == 0)
                    break;
            }
            if (prime[i] == j )
                Console.WriteLine(prime[i]);
        }
       
    }
}

Write a C# program to accept string from the user and replace all occurrences of character ‘a’ by ‘*’ symbol

using System;

class pro
{
    static void Main()
    {
        String sentence;
        Console.WriteLine("Enter a string: ");
        sentence=Console.ReadLine();
        char[] letter=sentence.ToCharArray();
        for(int i=0;i<sentence.Length;i++)
        {
            if(letter[i]=='a'|| letter[i]=='A')
                letter[i]='*';
        }
        String data=new String(letter);
        Console.WriteLine(data);
    }
}

Write a C# program to display whether the input character is a digit or alphabet

using System;

class Pro
{
    static void Main()
    {
        char ch;
        Console.WriteLine("Enter your input: ");
        ch = Convert.ToChar(Console.ReadLine());
        if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
            Console.WriteLine("You have entered an alphabet");
        else if (ch >= '0' && ch <= '9')
            Console.WriteLine("You have entered a digit");
        else
            Console.WriteLine("You have entered a special character");
    }
}

Write a C# program to display the multiplication table of a given number

using System;

class pro
{
    static void Main()
    {
        int n,i;
        Console.WriteLine("Enter an integer to find multiplication table: ");
        n=Convert.ToInt32(Console.ReadLine());
        for(i=1;i<=10;++i)
        {
        Console.WriteLine(n+"*"+i+"="+n*i);
        }
    }
}

Write a C# program to print the array elements

using System;

class Demo2
{
static void Main()
    {
        int[] arr=new int[10];
        int i, n;
        Console.WriteLine("Enter the array size: ");
        n=Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter the array elements:");
        for(i=0;i<n;i++)
        {
            arr[i]=int.Parse(Console.ReadLine());
        }
        Console.WriteLine("The array is.....");
        for(i=0;i<n;i++)
        {
            Console.WriteLine(arr[i]);
        }
    }

}

Write a C# program to calculate Gross Salary

  • Write a  C# program to accept basic salary from user. If basic salary>=5000 then hra=15% and da=150% of basic salary.If basic salary<5000 then hra=10% and da=110% of basic salary .Display the Gross salary


using System;
class Demo1
{
    static void Main()
    {
        double salary, hra = 0, da = 0;
        Console.WriteLine("Enter your salary: ");
        salary = Convert.ToDouble(Console.ReadLine());
        if (salary >= 5000)
        {
            hra = salary * 0.15;
            da = salary * 1.5;
        }
        else
        {
            hra = salary * 0.1;
            da = salary * 1.1;
        }
        Console.WriteLine("Gross Salary : " + (salary + hra + da));
    }
}

Write a C# program to accept ‘n’ numbers from user , store these numbers into an array. Find out maximum and minimum number from an Array

using System;
class Pro
{
    static void Main()
    {
        int[] num = new int[10];
        int i, n, max, min;
        Console.WriteLine("Enter the array size: ");
        n = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter the array elements: ");
        for (i = 0; i < n; i++)
        {
            num[i] = int.Parse(Console.ReadLine());
        }
        max = num[0];
        min = num[0];

        for (i = 0; i < n; i++)
        {
            if (num[i] > max)
            {
                max = num[i];
               
            }
            else if(num[i]<min)
            {
                min = num[i];
             
            }
        }
        Console.WriteLine("Max : " + max);
        Console.WriteLine("Min : " + min);
    }
}

Write a C# program to accept Four digit number from user and count zero , odd and even digits from the entered number

using System;

class Demo
{
    static void Main()
    {
        int num,digit;
        int zero=0,odd=0,even=0;
     
        Console.WriteLine("Enter a four digit number: ");
        num = Convert.ToInt32(Console.ReadLine());
       
        while(num > 0)
        {
            digit = num % 10;
            if (digit == 0)
                zero++;
            else if (digit %2== 0)
               even++;
            else
                odd++;
            num /= 10;

           
        }
        Console.WriteLine("No of zeroes: " + zero);
        Console.WriteLine("No of odds: " + odd);
        Console.WriteLine("No of evens: " + even);

    }
}

        

Thursday, 18 June 2015

Introduction to Java Programming Language

Java is a general-purpose, object-oriented language developed by Sun Microsystems of USA in 1991. Originally called Oak by James Gosling, one of the inventor of the language, Java was designed for the development of software for consumer electronic devices. The goal had a strong impact on the development team to make the language simple, portable and highly reliable.

Java Features


Compiled and Interpreted
Platform-Independent and Portable
Object-Oriented
Robust and Secure
Distributed
Simple, Small and Familiar
Multithreaded and Interactive
High Performance
Dynamic and Extensible
Ease of Development
Scalability and Performance
Monitoring and Manageability
Desktop Client

Miscellaneous Features


Core XML support
Supplementary Character support
JDBC Rowset

Enhancements in Java SE 6


Scripting Language Support
XML Processing and Web Services
JDBC 4.0 Support
Annotation-based Programming
Dynamic Compilation

Enhancements in Java SE 7


Language Enhancements
NIO 2.0
Parallel Programming
Dynamic Language Support

How Java Differs from C and C++ ?


Although Java was modeled after C and C++ languages, it differs from C and C++ in many ways. Java does not incorporate a number of features available in C and C++.

Java and C


1. Java does not include the C unique statement keywords sizeof and typedef.
2. Java does not contain the data type struct and union.
3. Java does not support an explicit pointer type.
4. Java does not define the type modifiers keywords auto, extern, register, signed and unsigned.
5. Java does not have a preprocessor and therefore we cannot use #define , #include and #ifdef statements.
6. Java requires that the functions with no arguments must be declared with empty parenthesis and not with the void keyword as done in C.
7. Java adds new operators such as instancef and >>> .
8. Java adds labeled break and continue statements.
9. Java adds many features required for OOP.

Java and C++


1. Java does not support operator overloading.
2. Java does not have template classess as in C++.
3. Java does not support multiple inheritance of classes. This is accomplished using a new feature called “Interface”.
4. Java does not support global variables. Every variable and method is declared within a class and forms part of that class.
5. Java does not use pointers.
6. Java has replaced the destructor function with a finalize() function.
7. There are no header files in Java.


Object-Oriented Programming

Fundamentals of Object-Oriented Programming


Object-Oriented programming is an approach that provides a way of modularizing programs by creating partitioned
memory area for both data and functions that can be used as templates for creating copies of such modules on demand.

Some of the features of Object-Oriented paradigm are :


1. Emphasis on data rather than procedure.
2. Programs are divided into what are known as objects.
3. Data structures are designed such that they characterize the objects.
4. Methods that operate on the data of an object are tied together in data structure.
5. Data is hidden and cannot be accessed by external functions.
6. Objects may communicate with each other through methods.
7. New data and methods can be added whenever necessary.
8. Follows bottom-up approach in program design.

Applications of OOP


The promising areas for application of OOP include:

Real-time systems
Simulation and modeling
Object-oriented databases
Hypertext, hypermedia and expertext
AI and expert systems
Neutral networks and parallel programming
Decision support and office automation system
CIM / CAD / CAD system