Author: admin

  • Java String Pattern: 5

    Java String Pattern: 5

    In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.

    String Pattern:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int i, j;
        String str;
        char[] ch;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the string: ");
        str = sc.nextLine();
    
        ch = str.toCharArray();
    
        for (i = ch.length - 1; i >= 0; i--)
        {
          for (j = 0; j <= i; j++)
            System.out.print(ch[j] + " ");
    
          System.out.println();
        }
      }
    }

    Enter the string: SIMPLE
    S I M P L E
    S I M P L
    S I M P
    S I M
    S I
    S


  • Java String Pattern: 4

    Java String Pattern: 4

    In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.

    String Pattern:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int i, j;
        String str;
        char[] ch;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the string: ");
        str = sc.nextLine();
    
        ch = str.toCharArray();
    
        for (i = 0; i < ch.length; i++)
        {
          for (j = 0; j <= i; j++)
            System.out.print(ch[j] + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the string: SIMPLE
    S
    S I
    S I M
    S I M P
    S I M P L
    S I M P L E


  • Java String Pattern: 3

    Java String Pattern: 3

    In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.

    String Pattern:

    public class Main
    {
      public static void main(String args[])
      {
        String str = "SIMPLE";
        int i, j, k;
        int length = str.length();
    
        for (i = 0; i < length; i++)
        {
          for (j = length - 1; j > i; j--)
          {
            System.out.print("  ");
          }
    
          for (k = 0; k <= i; k++)
          {
            System.out.print(str.charAt(k) + " ");
          }
    
          System.out.println();
        }
      }
    }

    Output:

              S
            S I
          S I M
        S I M P
      S I M P L
    S I M P L E

  • Java String Pattern: 2

    Java String Pattern: 2

    In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.

    String Pattern:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        String str;
        int i, j;
        char[] ch;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter a Word: ");
        str = sc.nextLine();
    
        ch = str.toCharArray();
        int strLength = ch.length;
    
        for (i = 0; i < strLength; i++)
        {
          for (j = 1; j <= strLength; j++)
          {
            System.out.print(str.charAt(strLength - j) + " ");
          }
    
          System.out.println();
        }
      }
    }

    Output:

    Enter a Word: SIMPLE
    E L P M I S
    E L P M I S
    E L P M I S
    E L P M I S
    E L P M I S
    E L P M I S


  • Java String Pattern: 1

    Java String Pattern: 1

    In this tutorial, we will go through the string pattern program in java. Before that, you may go through the following topic in java.

    String Pattern:

    public class Main
    {
      public static void main(String args[])
      {
        String str = "SIMPLE";
        int length = str.length();	//length of the string
    
        for (int i = 0; i < length; i++)
        {
          for (int j = 0; j < length; j++)
          {
            System.out.print(str.charAt(j) + " ");
          }
    
          System.out.println();
        }
      }
    }

    Output:

    S I M P L E
    S I M P L E
    S I M P L E
    S I M P L E
    S I M P L E
    S I M P L E


  • Algorithm and Flowchart to find Fibonacci series

    In this tutorial, we will write an algorithm to find the Fibonacci series, we will also learn to draw the flowchart to find the Fibonacci series for a number. You may go through the following topic first.

    Let us first understand what is fibonacci series.

    Fibonacci series is the series of numbers where the next number is achieved by the addition of the previous two numbers. The initial addition of two numbers is 0 and 1. For example: 0,1,1,2,3,5,8,13….etc.

    Let us start with a flowchart of a fibonacci series.

    Flowchart to calculate the fibonacci series

    flowchart of a Fibonacci series

    The above flowchart diagram is to find the Fibonacci series.


    Algorithm of Fibonacci Series

    Step 1: START
    Step 2: Declare variable n1, n2, sum, n, i
    Step 2: Initialize variables:
    n1 = 0, n2 = 1, i = 2
    Step 3:  Read n
    Step 4: Repeat this step until i <= n:
    sum = n1 + n2
    print sum
    n1 = n2
    n2 = sum
    i = i + 1
    Step 5: STOP

    This is the algorithm and flowchart of fibonacci series. If you want to understand through code, you may follow the below link:


  • Currency Conversion Program in C

    In this tutorial, we will write a C program for currency conversion. Before that, you may go through the following topic in C.

    Explanation: In this program, there is a use of switch statements in C. The program gives the user choice for the conversion. For this example, we have taken four currencies those are Rupee, Dollar, Pound and Euro.

    There are four cases for each currency conversion. You can modify the value of a currency with the actual current value.


    Currency Conversion Program in C

    #include <stdio.h>
    
    int main()
    {
      float amount;
      float rupee, dollar, pound, euro;
      int choice;
    
      printf("Following are the Choices:");
      printf("\nEnter 1: Ruppe");
      printf("\nEnter 2: Dollar");
      printf("\nEnter 3: Pound");
      printf("\nEnter 4: Euro");
    
      printf("\nEnter your choice: ");
      scanf("%d", &choice);
    
      printf("Enter the amount you want to convert?\n");
      scanf("%f", &amount);
    
      switch (choice)
      {
        case 1: // Ruppe Conversion
            dollar = amount / 70;
            printf("%.2f Rupee =  %.2f dollar", amount, dollar);
    
            pound = amount / 88;
            printf("\n%.2f Rupee =  %.2f pound", amount, pound);
    
            euro = amount / 80;
            printf("\n%.2f Rupee =  %.2f euro", amount, euro);
            break;
    
        case 2: // Dollar Conversion
            rupee = amount * 70;
            printf("\n%.2f Dollar =  %.2f rupee", amount, rupee);
    
            pound = amount *0.78;
            printf("\n%.2f Dollar =  %.2f pound", amount, pound);
    
            euro = amount *0.87;
            printf("\n%.2f Dollar =  %.2f euro", amount, euro);
            break;
    
        case 3: // Pound Conversion
            rupee = amount * 88;
            printf("\n%.2f Pound =  %.2f rupee", amount, rupee);
    
            dollar = amount *1.26;
            printf("\n%.2f Pound =  %.2f dollar", amount, dollar);
    
            euro = amount *1.10;
            printf("\n%.2f Pound =  %.2f euro", amount, euro);
            break;
    
        case 4: // Euro Conversion
            rupee = amount * 80;
            printf("\n%.2f Euro =  %.2f rupee", amount, rupee);
    
            dollar = amount *1.14;
            printf("\n%.2f Euro =  %.2f dollar", amount, dollar);
    
            pound = amount *0.90;
            printf("\n.2%f Euro =  %.2f pound", amount, pound);
            break;
    
         //Default case
        default:
            printf("\nInvalid Input");
      }
    
      return 0;
    }

    Output:

    Following are the Choices:
    Enter 1: Ruppe
    Enter 2: Dollar
    Enter 3: Pound
    Enter 4: Euro
    Enter your choice: 2
    Enter the amount you want to convert?
    7

    7.00 Dollar = 490.00 rupee
    7.00 Dollar = 5.46 pound
    7.00 Dollar = 6.09 euro

    There is a use of %.2f” which means only two digits after the decimal value will be displayed.


  • C Program to Find the Area of a Rectangle

    In this tutorial, we will write a C program to find the area of a rectangle. Before that, you may go through the following topic in C.

    Explanation: The program asks the user to enter the value of length and breadth as an input. Then simply using the formula (area = length * breadth), we calculate the area of a rectangle in C.


    C Program to find the area of a Rectangle

    #include <stdio.h>
    
    int main()
    {
      int len, br, area;
    
      printf("Enter the length: ");
      scanf("%d", &len);
      printf("Enter the breadth: ");
      scanf("%d", &br);
    
      area = len * br;
      printf("Area of a rectangle: %d", area);
    
      return 0;
    }

    Output:

    Enter the length: 2
    Enter the breadth: 5
    Area of a rectangle: 10

    You may change the data type int to float or any other as per your requirements.


  • Half Repeated Character Pattern in Java

    Half Repeated Character Pattern in Java

    In this tutorial, we will go through alphabet pattern programs in java programming. Before that, you may go through the following topic in java.


    Half Repeated Character 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 no. of rows: ");
        rows = sc.nextInt();
    
        for (i = 0; i <= rows; i++)
        {
          int alphabet = 65;
          for (j = 0; j < i; j++)
            System.out.print(" ");
    
          for (k = i; k <= rows; k++)
            System.out.print((char)(alphabet + k));
    
          System.out.println();
        }
        for (i = rows; i >= 0; i--)
        {
          int alphabet = 65;
          for (j = 0; j < i; j++)
            System.out.print(" ");
    
          for (k = i; k <= rows; k++)
            System.out.print((char)(alphabet + k));
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the no. of rows: 5
    ABCDEF
     BCDEF
      CDEF
       DEF
        EF
         F
         F
        EF
       DEF
      CDEF
     BCDEF
    ABCDEF

  • 2 Different Alphabet Patterns in Java (half hourglass)

    2 Different Alphabet Patterns in Java (half hourglass)

    In this tutorial, we will go through two different alphabet pattern programs in java programming. Before that, you may go through the following topic in java.


    2 different Alphabet pattern program in Java

    Both of the programs below take the number of rows as the user input and using for loop it prints the desired output.

    Pattern 1:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        //upper part
        for (i = rows; i >= 0; i--)
        {
          int character = 65;
          for (j = 0; j <= i; j++)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
        //lower part
        for (i = 0; i <= rows; i++)
        {
          int character = 65;
          for (j = 0; j <= i; j++)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the no. of rows: 5
    A B C D E F
    A B C D E
    A B C D
    A B C
    A B
    A
    A
    A B
    A B C
    A B C D
    A B C D E
    A B C D E F


    Pattern 2:

    import java.util.Scanner;
    
    public class Main
    {
      public static void main(String args[])
      {
        int rows, i, j;
        Scanner sc = new Scanner(System.in);
    
        System.out.print("Enter the no. of rows: ");
        rows = sc.nextInt();
    
        //upper part
        for (i = rows; i >= 0; i--)
        {
          int character = 65;
          for (j = i; j >= 0; j--)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
        //lower part
        for (i = 0; i <= rows; i++)
        {
          int character = 65;
          for (j = i; j >= 0; j--)
            System.out.print((char)(character + j) + " ");
    
          System.out.println();
        }
      }
    }

    Output:

    Enter the no. of rows: 5
    F E D C B A
    E D C B A
    D C B A
    C B A
    B A
    A
    A
    B A
    C B A
    D C B A
    E D C B A
    F E D C B A