The if..else..if ladder allows you to execute a block code among many alternatives. If you are checking on the value of a single variable in if...else...if, it is better to use switchstatement.

The switch statement is often faster than nested if...else (not always). Also, the syntax of switch statement is cleaner and easy to understand.

Syntax of switch…case

switch (n)
    case constant1:
        // code to be executed if n is equal to constant1;

    case constant2:
        // code to be executed if n is equal to constant2;
        // code to be executed if n doesn't match any constant

When a case constant is found that matches the switch expression, control of the program passes to the block of code associated with that case.

Suppose, the value of n is equal to constant2. The compiler executes the statements after case constant2: until break is encountered. When break statement is encountered, switch statement terminates.

switch Statement Flowchart

Flowchart of switch statement


Example: switch Statement

// Program to create a simple calculator
#include <stdio.h>

int main() {

    char operator;
    double firstNumber,secondNumber;

    printf("Enter an operator (+, -, *, /): ");
    scanf("%c", &operator);

    printf("Enter two operands: ");
    scanf("%lf %lf",&firstNumber, &secondNumber);

        case '+':
            printf("%.1lf + %.1lf = %.1lf",firstNumber, secondNumber, firstNumber+secondNumber);

        case '-':
            printf("%.1lf - %.1lf = %.1lf",firstNumber, secondNumber, firstNumber-secondNumber);

        case '*':
            printf("%.1lf * %.1lf = %.1lf",firstNumber, secondNumber, firstNumber*secondNumber);

        case '/':
            printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/secondNumber);

        // operator is doesn't match any case constant (+, -, *, /)
            printf("Error! operator is not correct");

    return 0;


Enter an operator (+, -, *,): -
Enter two operands: 32.5
32.5 - 12.4 = 20.1

The  operator entered by the user is stored in operator variable. And, two operands 32.5and 12.4 are stored in variables firstNumber and secondNumber respectively.

Then, control of the program jumps to

printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/firstNumber);

Finally, the break statement terminates the switch statement.


Matrices and Determinants
On this page:

Introduction and Examples
Matrix Addition and Subtraction
Matrix Multiplication
The Transpose of a Matrix
The Determinant of a Matrix
The Inverse of Matrix
Systems of Linear Equations
The Inverse Matrix Method
Cramer’s Rule
Introduction and Examples
DEFINITION: A matrix is defined as an ordered rectangular array of numbers. They can be used to represent systems of linear equations, as will be explained below.

Here are a couple of examples of different types of matrices:

Symmetric Diagonal Upper Triangular Lower Triangular Zero Identity
Symmetric Matix Diagonal Matrix Upper Triangular Matix Lower Triangular Matix Zero Matix Identity Matix
And a fully expanded m×n matrix A, would look like this:

n×n matrix
… or in a more compact form: m×n simplified

Matrix Addition and Subtraction
DEFINITION: Two matrices A and B can be added or subtracted if and only if their dimensions are the same (i.e. both matrices have the same number of rows and columns. Take:

matrices A&B
If A and B above are matrices of the same type then the sum is found by adding the corresponding elements aij + bij .

Here is an example of adding A and B together.

Sum of matrices A&B
If A and B are matrices of the same type then the subtraction is found by subtracting the corresponding elements aij − bij.

Here is an example of subtracting matrices.

Subtraction of A&B
Now, try adding and subtracting your own matrices.

Addition/subtraction Top
Matrix Multiplication
DEFINITION: When the number of columns of the first matrix is the same as the number of rows in the second matrix then matrix multiplication can be performed.

Here is an example of matrix multiplication for two 2×2 matrices.

Matrix multiplication 2×2
Here is an example of matrix multiplication for two 3×3 matrices.

Matrix multiplication 3×3
Now lets look at the n×n matrix case, Where A has dimensions m×n, B has dimensions n×p. Then the product of A and B is the matrix C, which has dimensions m×p. The ijth element of matrix C is found by multiplying the entries of the ith row of A with the corresponding entries in the jth column of B and summing the n terms. The elements of C are:

Matrix multiplication for n×n
Note: That A×B is not the same as B×A

Now, try multiplying your own matrices.

Matrix multiplication Top
Transpose of Matrices
DEFINITION: The transpose of a matrix is found by exchanging rows for columns i.e. Matrix A = (aij) and the transpose of A is:

AT = (aji) where j is the column number and i is the row number of matrix A.

For example, the transpose of a matrix would be:

Transpose of matrix
In the case of a square matrix (m = n), the transpose can be used to check if a matrix is symmetric. For a symmetric matrix A = AT.

Symmetric matrix
Now try an example.

Transpose of a matrix Top
The Determinant of a Matrix
DEFINITION: Determinants play an important role in finding the inverse of a matrix and also in solving systems of linear equations. In the following we assume we have a square matrix (m = n). The determinant of a matrix A will be denoted by det(A) or |A|. Firstly the determinant of a 2×2 and 3×3 matrix will be introduced, then the n×n case will be shown.

Determinant of a 2×2 matrix
Assuming A is an arbitrary 2×2 matrix A, where the elements are given by:

Matrix A
then the determinant of a this matrix is as follows:

Det A
Now try an example of finding the determinant of a 2×2 matrix yourself.

Determinant of 2×2
Determinant of a 3×3 matrix
The determinant of a 3×3 matrix is a little more tricky and is found as follows (for this case assume A is an arbitrary 3×3 matrix A, where the elements are given below).

Matrix A
then the determinant of a this matrix is as follows:

Det of A
Now try an example of finding the determinant of a 3×3 matrix yourself.

Determinant of 3×3
Determinant of a n×n matrix
For the general case, where A is an n×n matrix the determinant is given by:

Matrix A n×n
Where the coefficients αij are given by the relation:

alpha coefficient
where βij is the determinant of the (n-1) × (n-1) matrix that is obtained by deleting row i and column j. This coefficient αij is also called the cofactor of aij.

The Inverse of a Matrix
DEFINITION: Assuming we have a square matrix A, which is non-singular (i.e. det(A) does not equal zero), then there exists an n×n matrix A-1 which is called the inverse of A, such that this property holds:

AA-1 = A-1A = I, where I is the identity matrix.

The inverse of a 2×2 matrix
Take for example a arbitury 2×2 Matrix A whose determinant (ad − bc) is not equal to zero.

2×2 matrix
where a,b,c,d are numbers, The inverse is:

Inverse of 2×2
Now try finding the inverse of your own 2×2 matrices.

Inverse of 2×2
The inverse of a n×n matrix
The inverse of a general n×n matrix A can be found by using the following equation.

Where the adj(A) denotes the adjoint (or adjugate) of a matrix. It can be calculated by the following method:

Given the n×n matrix A, define
B = bij
to be the matrix whose coefficients are found by taking the determinant of the (n-1) × (n-1) matrix obtained by deleting the ith row and jth column of A. The terms of B (i.e. B = bij) are known as the cofactors of A.
Define the matrix C, where
cij = (−1)i+j bij.
The transpose of C (i.e. CT) is called the adjoint of matrix A.
Lastly to find the inverse of A divide the matrix CT by the determinant of A to give its inverse.

Now test this method with finding the inverse of your own 3×3 matrices.

Inverse of 3×3 Top
Solving Systems of Equations using Matrices
DEFINITION: A system of linear equations is a set of equations with n equations and n unknowns, is of the form of

n×n Systems of equations
The unknowns are denoted by x1, x2, …, xn and the coefficients (a and b above) are assumed to be given. In matrix form the system of equations above can be written as:

n×n Systems of equations
A simplified way of writing above is like this: Ax = b

Now, try putting your own equations into matrix form.

Putting equations into matrices
After looking at this we will now look at two methods used to solve matrices. These are:

Inverse Matrix Method
Cramer’s Rule
Inverse Matrix Method
DEFINITION: The inverse matrix method uses the inverse of a matrix to help solve a system of equations, such like the above Ax = b. By pre-multiplying both sides of this equation by A-1 gives:

Ax=b derivation
or alternatively

Ax=b derivation
So by calculating the inverse of the matrix and multiplying this by the vector b we can find the solution to the system of equations directly. And from earlier we found that the inverse is given by

From the above it is clear that the existence of a solution depends on the value of the determinant of A. There are three cases:

If the det(A) does not equal zero then solutions exist using Ax=b derivation
If the det(A) is zero and b=0 then the solution will be not be unique or does not exist.
If the det(A) is zero and b=0 then the solution can be x = 0 but as with 2. is not unique or does not exist.
Looking at two equations we might have that

Written in matrix form would look like

and by rearranging we would get that the solution would look like

Now try solving your own two equations with two unknowns.

Inverse Method 2×2
Similarly for three simultaneous equations we would have:

Written in matrix form would look like

and by rearranging we would get that the solution would look like

Now try solving your own three equations with three unknowns.

Inverse Method 3×3 Top
Cramer’s Rule
DEFINITION: Cramer’s rule uses a method of determinants to solve systems of equations. Starting with equation below,

n×n Systems of equations
The first term x1 above can be found by replacing the first column of A by b×n. Doing this we obtain:

n×n Systems of equations
Similarly for the general case for solving xr we replace the rth column of A by b×n and expand the determinant. This method of using determinants can be applied to solve systems of linear equations. We will illustrate this for solving two simultaneous equations in x and y and three equations with 3 unknowns x, y and z.

Two simultaneous equations in x and y
2×2 equations
To solve use the following:

or simplified:

Now try solving two of your own equations.

Cramers 2×2
Three simultaneous equations in x, y and z
ax + by + cz = p
dx + ey + fz = q
gx + hy + iz = r

To solve use the following:

Now try solving your own three equations.


package beginnersbook.com;
import java.io.*;
public class ReadFileDemo {
   public static void main(String[] args) {         
      //Specify the path of the file here
      File file = new File(“C://myfile.txt”);
      BufferedInputStream bis = null;
      FileInputStream  fis= null;
          //FileInputStream to read the file
          fis = new FileInputStream(file);
          /*Passed the FileInputStream to BufferedInputStream
           *For Fast read using the buffer array.*/
          bis = new BufferedInputStream(fis);
          /*available() method of BufferedInputStream
           * returns 0 when there are no more bytes
           * present in the file to be read*/
          while( bis.available() > 0 ){            
       }catch(FileNotFoundException fnfe)
            System.out.println(“The specified file not found” + fnfe);
        catch(IOException ioe)
            System.out.println(“I/O Exception: ” + ioe); 
               if(bis != null && fis!=null)
             }catch(IOException ioe)
                  System.out.println(“Error in InputStream close(): ” + ioe);


A computer is a programmable machine. The two principal characteristics of a computer are: It responds to a specific set of instructions in a well-defined manner and it can execute a prerecorded list of instructions (a program).

Modern Computers Defined

Modern computers are electronic and digital. The actual machinery — wires, transistors, and circuits  is called hardware; the instructions and data are called software.

Computer System

All general-purpose computers require the following hardware components:

In addition to these components, many others make it possible for the basic components to work together efficiently. For example, every computer requires a bus that transmits data from one part of the computer to another.

Computer Classification: By Size and Power

Most people associate a personal computer (PC) with the phrase computer.  A PC is a small and relatively inexpensive computer designed for an individual use. PCs are based on the microprocessor technology that enables manufacturers to put an entire CPU on one chip.

Personal computers at home can be used for a number of different applications including games, word processing, accounting and other tasks.

Computers are generally classified by size and power as follows, although there is considerable overlap. The differences between computer classifications generally get smaller as technology advances, creating smaller and more powerful and cost-friendly components.

  • Personal computer: a small, single-user computer based on a microprocessor. In addition to the microprocessor, a personal computer has a keyboard for entering data, a monitor for displaying information, and a storage device for saving data.
  • Workstation: a powerful, single-user computer. A workstation is like a personal computer, but it has a more powerful microprocessor and a higher-quality monitor.
  • Minicomputer: a multi-user computer capable of supporting from 10 to hundreds of users simultaneously.
  • Mainframe: a powerful multi-user computer capable of supporting many hundreds or thousands of users simultaneously.
  • Supercomputer: an extremely fast computer that can perform hundreds of millions of instructions per second.
  • Webopedia Stuydy Guide Recommended Reading: Webopedia’s Computer Architecture Study Guide is an introduction to computer system basics.