Java String Pattern: 4

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