Tag: java string pattern

  • Java String Pattern: 10

    Java String Pattern: 10

    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 = "Simple2Code";
        int n = 6;
        int x = 0;
        int i, j, k;
    
        for (i = 0; i < n; i++)
        {
          for (j = 0; j < i; j++)
            System.out.print("  ");
    
          for (k = 0; k < n - i; k++)
          {
            System.out.print(str.charAt(x++) + " ");
    
            if (x == str.length())
              x = 0;
    
          }
    
          System.out.println();
        }
      }
    }

    Output:

    S i m p l e
      2 C o d e
        S i m p
          l e 2
            C o
              d

  • Java String Pattern: 9

    Java String Pattern: 9

    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 = "SIMPLE2CODE";
        int n = 6;
        int x = 0;
        int i, j;
    
        for (i = 0; i < n; i++)
        {
          for (j = 0; j <= i; j++)
          {
            System.out.print(str.charAt(x++) + " ");
    
            if (x == str.length())
              x = 0;
    
          }
    
          System.out.println();
        }
      }
    }

    Output:

    S
    I M
    P L E
    2 C O D
    E S I M P
    L E 2 C O D


  • Java String Pattern: 8

    Java String Pattern: 8

    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 arr = "SIMPLE2CODE";
        int n = 6;
        int x = 0;
        int i, j, k;
    
        for (i = 0; i < n; i++)
        {
          for (j = n - 1; j > i; j--)
            System.out.print("  ");
    
          for (k = 0; k <= i; k++)
          {
            System.out.print(arr.charAt(x++) + " ");
            if (x == arr.length())
              x = 0;
          }
    
          System.out.println();
        }
      }
    }

    Output:

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

  • Java String Pattern: 7

    Java String Pattern: 7

    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 I M P L E
      S I M P L
        S I M P
          S I M
            S I
              S

  • Java String Pattern: 6

    Java String Pattern: 6

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

    Character Pattern Programs in Java

    The program below takes a user input for a word from the user using Scanner class and prints that word in various patterns format in java. The following are the three alphabet patterns in java with string input.

    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();
        //upper part
        for (i = 0; i < ch.length; i++)
        {
          for (j = 0; j < i; j++)
            System.out.print(ch[j] + " ");
    
          System.out.println();
        }
        //lower part
        for (i = ch.length; i >= 0; 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
    S I M P L
    S I M P
    S I M
    S I
    S


  • 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