Blog

  • Block Diagram of a Computer

    Computer Block Diagram: Block diagram of computer displays the structural or pictorial representation of a computer system. In other words, a block diagram of the computer will let you visualize how the computer works starting from inputting the data to retrieving the output.

    The following is the block diagram of computer system.

    Block Diagram of Computer

    The Computer System works with the combination of the following three components.

    • Input Unit
    • Central Processing Unit
      • ALU – Arithmetic Logic Unit
      • CU – Control Unit
    • Memory Unit
      • Primary memory
      • Secondary memory
    • Output Unit

    Explain block diagram of a computer

    Input Unit

    The input units are the input devices attached to a system through which the users enter the instruction for the computer to perform. These devices are the mouse, keyboard, scanner, etc. We can say that these devices are the means of communication between the user and the system.

    The computer takes the input as the raw data that is the binary (machine-readable form) and performs the further processing. Later, when the processing is complete, it gives the output in output devices such as through monitors, printers, etc.


    Central Processing Unit (CPU)

    The CPU is the brain/heart of the computer. The computer is nothing without the CPU. All the instruction that is given by the user to the computer is processed by the CPU. The CPU gets the input from the user or the set of instructions and produces the output accordingly.

    It is an electronic hardware device that performs all the operations such as arithmetic and logical operations. It is responsible for activation and controlling the operation of other units.

    Block diagram of CPU:

    block diagram of CPU

    It consists of two major components and they are:

    • Arithmetic and Logic Unit (ALU)
    • Control Unit (CU)

    Arithmetic and Logic Unit (ALU):

    In this part of the CPU, all the arithmetical and logical operations are performed.

    The arithmetic operations such as addition, subtraction, multiplication, and division are performed in the arithmetic section, and the logical operation such as AND, OR, Equal, Less than, Greate than, etc are performed on the logical section. Logical is also responsible for comparing, matching, selecting, etc operations.

    Control Unit (CU):

    From the name itself, we can conclude that the control unit (CU) controls all the activities or operations which are performed inside the computer system.

    As you can see in the diagram above the control unit is connected to the memory unit of the system that means it receives instructions or information directly from the main memory of the computer. The control unit converts those instructions into a set of signals and then transmits those signals to the other part of the computer system for further processing.


    Memory Unit

    The memory unit is one of the major components of a computer system or component of a digital computer that is also called a storage unit. The data and instructions are stored in a memory unit for further after and before processing. The intermediate and final results are stored in this unit.

    The instructions are transmitted to different parts of the system from the memory unit. There are two types of memory units and they are:

    Primary Storage Unit:

    The primary memory stores the temporary data or instruction. They cannot store a huge amount of data. It is used to store the instruction that is currently being performed or the immediate calculation result. Once the power to the computer is cut off, the data in this primary will be lost.

    It is also known as the Main memory or the Temporary memory. One example of this type of memory is RAM(Random Access Memory).

    Secondary Storage Unit:

    When we need to store the data permanently for future processing then we use the secondary memory of the computer. It is exactly the opposite of primary memory. The data is not lost even if the power supply fails.

    It is also called secondary or auxiliary storage or permanent storage. One example of this type of memory is a Hard Disk or an SSD (Solid-state drive).

    Note: The CPU can directly access the primary memory but the secondary memory is not accessible to the CPU directly. The data from the secondary memory is first loaded to the RAM (primary memory) and then the CPU can access it.


    Output Unit

    The output units are the output devices attached to a system through which the users can see the result of the inputted data. These devices are printers, monitors, etc.

    The data is first stored in the memory and then converted to human-readable form from binary code and then displayed on the output devices.

    The output unit provides the result into two forms such as soft copy or hard copy. The monitor is used for a soft copy as it displays on the screen, whereas the printer is used for hard copy as it prints the output on the paper.


  • Right Arrow Star Pattern in Java

    Right Arrow Star Pattern in Java

    In this tutorial, we will write a java program to print right arrow star pattern. Before that, you may go through the following topic in java.


    Right Arrow Star Pattern in Java

    This is a program on the arrowhead pattern in java. The program takes a user input for the number of rows in a pattern and using for loop, it displays the pattern.

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j, k;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Output:\n");
    
        //upper part of the arrow head
        for (i = 1; i < rows; i++)
        {
          for (j = 0; j < i; j++)
            System.out.print(" ");
    
          for (k = 0; k < i; k++)
            System.out.print("*");
    
          System.out.println();
        }
    
        //lower part of the arrow head
        for (i = 0; i < rows; i++)
        {
          for (j = 0; j < rows - i; j++)
            System.out.print(" ");
    
          for (k = 0; k < rows - i; k++)
            System.out.print("*");
    
          System.out.println();
        }
      }
    }

    Output:

    Right Arrow Star Pattern in Java

    User Input for Character

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j, k;
        char symbol;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();
        System.out.print("Enter the symbol for the pattern: ");
        symbol = sc.next().charAt(0);
    
        System.out.print("Output:\n");
    
        //upper part of the arrow head
        for (i = 1; i < rows; i++)
        {
          for (j = 0; j < i; j++)
            System.out.print(" ");
    
          for (k = 0; k < i; k++)
            System.out.print(symbol);
    
          System.out.println();
        }
    
        //lower part of the arrow head
        for (i = 0; i < rows; i++)
        {
          for (j = 0; j < rows - i; j++)
            System.out.print(" ");
    
          for (k = 0; k < rows - i; k++)
            System.out.print(symbol);
    
          System.out.println();
        }
      }
    }

    Output:

    Right Arrow Star Pattern in Java 2

  • Right Angle Triangle Character Pattern in Java: Pattern 1

    Right Angle Triangle Character Pattern in Java: Pattern 1

    In this tutorial, we will write a program to display a right-angle triangle pattern in java using the alphabet. Before that, you may go through the following topic in java.

    The program below takes the user input from the user for the number of rows and display the right triangle character pattern in various character orders.

    Right angled triangle pattern

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        int ch = 64;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Output:\n");
        for (i = 1; i <= rows; i++)
        {
          for (j = 1; j <= i; j++)
            System.out.print((char)(i + ch)+" ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the number of rows: 6
    Output:
    A
    B B
    C C C
    D D D D
    E E E E E
    F F F F F F


  • Inverted Right Triangle Alphabet Pattern in Java: Pattern 1

    Inverted Right Triangle Alphabet Pattern in Java: Pattern 1

    In this tutorial, we will write a java program to display the reverse right triangle pattern using the alphabet. These are character pattern programs in java. Before that, you may go through the following topic in java.

    The programs below take the user input from the user for the number of rows and display the reverse right triangle character pattern in various character orders.

    This program can also be called the inverted half pyramid in java or Floyd’s triangle alphabet pattern in java.

    Reverse right angled triangle pattern

    In this program, the decrement of the Alphabet starts from the right corner of the pattern.

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        int ch = 64;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Output:\n\n");
        for (i = rows; i >= 1; i--)
        {
          for (j = 1; j <= i; j++)
          {
            System.out.print((char)(j + ch));
          }
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the number of rows: 6
    Output:


    ABCDEF
    ABCDE
    ABCD
    ABC
    AB
    A


  • Inverted Hourglass Pattern in Java using Numbers

    Inverted Hourglass Pattern in Java using Numbers

    In this tutorial, we will write a java program to print the inverted hourglass pattern using numbers. Before that, you may go through the following topic in java.


    Inverted Hourglass Pattern in Java

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String[] args)
      {
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        int n = sc.nextInt();
        int nsp = 2 *n - 1;
    
        int nr = 2 *n + 1;
        int num = n;
        int a = 0;
    
        for (int i = 1; i <= nr; i++)
        {
          if (i > n + 1)
            a = nr - i + 1;
          else
            a = i;
    
          //numbers
          for (int cst = 1; cst <= a; cst++)
          {
            System.out.print(num);
            num--;
          }
    
          //Spaces
          for (int csp = 1; csp <= nsp; csp++)
          {
            System.out.print(" ");
          }
    
          for (int cst = 1; cst <= a; cst++)
          {
            num++;
            if (num != 0)
              System.out.print(num);
          }
    
          if (i <= (nr) / 2)
            nsp -= 2;
          else
            nsp += 2;
    
          System.out.println();
        }
      }
    }

    Output:

    Inverted Hourglass Pattern in Java

  • Similar Alphabet Pyramid Pattern in Java

    Similar Alphabet Pyramid Pattern in Java

    In this tutorial, we will write an alphabet triangular pattern in java where the characters or letters are every row have the same alphabet. Before that, you may go through the following topic in java.

    Example:

    Rows Input: 5
    Output:
           A
          B B
         C C C
        D D D D
       E E E E E
    

    Alphabet Pyramid Pattern in Java

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        System.out.print("Output:\n");
        for (i = 1; i <= rows; i++)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print(" ");
    
          for (j = 1; j <= i; j++)
            System.out.print((char)(char)(i + 64) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the number of rows: 8
    Output:
           A
          B B
         C C C
        D D D D
       E E E E E
      F F F F F F
     G G G G G G G
    H H H H H H H H

  • Java Program to print Half Pyramid using Alphabets in Increasing order

    Java Program to print Half Pyramid using Alphabets in Increasing order

    In this tutorial, we will write a program to display half alphabet pyramid patterns in java. Before that, you may go through the following topic in java.

    Example:

    Rows Input: 5
    Output:
    A
    A B
    A B C
    A B C D
    A B C D E

    This program is also known as right-angled triangle patterns using the alphabet in java as the right angle is formed on the right side of the pattern.


    Java Program to print Half Pyramid using Alphabets

    The program takes a user input for the number of rows to be displayed on the screen. The Alphabet starts from A and increases at every row such as A, Ab, ABC, and so on.

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        char ch;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        System.out.print("Output:\n");
        for (i = 1; i <= rows; i++)
        {
          ch = 'A';
          for (j = 1; j <= i; j++)
          {
            System.out.print(" " + ch++);
          }
    
          System.out.print("\n");
        }
      }
    }

    Output:

    Enter the number of rows: 7
    Output:
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F
    A B C D E F G

  • Reverse Pyramid with Alphabet in Java

    Reverse Pyramid with Alphabet in Java

    In this tutorial, we will write a reverse alphabet triangle pattern in java. Before that, you may go through the following topic in java.

    The program takes a user input for the number of rows to be printed. Then the inverted alphabet pattern is displayed on the screen.


    Java Program to display the Reverse Pyramid pattern with Alphabet

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        System.out.print("Output:\n");
        for (i = rows; i >= 1; i--)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print("  ");
    
          for (j = 1; j <= 2 *i - 1; j++)
          {
            if (j <= i)
              System.out.print((char)(char)(j + 64) + " ");
            else
              System.out.print((char)(char)(2 *i - j + 64) + " ");
          }
          System.out.println();
        }
      }
    }
    Enter the number of rows: 5
    Output:
    A B C D E D C B A
      A B C D C B A
        A B C B A
          A B A
            A

  • Alphabet Pyramid Pattern in Java: pattern 1

    Alphabet Pyramid Pattern in Java: pattern 1

    In this tutorial, we will write a Java program to display alphabet pyramid patterns. Before that, you may go through the following topic in java.

    We will look at pyramid patterns in java using alphabets/letters/characters.

    Pyramid triangle alphabet

    This is a mirror image pattern of letters in java.

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner scan = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = scan.nextInt();
    
        for (i = 1; i <= rows; i++)
        {
          for (j = 1; j <= rows - i; j++)
            System.out.print(" ");
    
          for (j = 1; j <= i; j++)
            System.out.print((char)(j + 64));
    
          for (j = i - 1; j >= 1; j--)
            System.out.print((char)(j + 64));
    
          System.out.println();
        }
      }
    }

    Enter the number of rows: 6
         A
        ABA
       ABCBA
      ABCDCBA
     ABCDEDCBA
    ABCDEFEDCBA
  • Hourglass Star Pattern in Java

    Hourglass Star Pattern in Java

    In this tutorial, we will write a java program to print sandglass star patterns. Before that, you may go through the following topic in java.

    The program below takes a user input for the number of rows needed and then in decreasing order of the first half is printed and then the increasing order of the second half of the sandglass is printed.

    This is an hourglass pattern program in java or you can say sandglass pattern program using a star.

    Input of row: 4  
    * * * *
     * * * 
      * * 
       *  
       * 
      * * 
     * * * 
    * * * *

    Hourglass Star Pattern in Java

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String[] args)
      {
        int rows, i, j, k;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();
    
        System.out.print("Output: \n\n");
        //upper half
        for (i = 1; i <= rows; i++)
        {
          for (k = 1; k <= i - 1; k++)
          {
            System.out.print("*" + " ");
          }
          for (j = 1; j <= rows - i + 1; j++)
          {
            System.out.print("*");
          }
          System.out.println();
        }
    
        //lower half
        for (i = rows - 1; i >= 1; i--)
        {
          for (k = 1; k <= i - 1; k++)
          {
            System.out.print(" ");
          }
          for (j = i; j <= rows; j++)
          {
            System.out.print("*" + " ");
          }
          System.out.println();
        }
      }
    }

    Output:

    Hourglass Star Pattern in Java