Tuesday, 10 November 2020

Java String Pattern Program

/*Program to display the String entered by the user in the following pattern:
J
JA
JAV
JAVA
*/

import java.util.*;
public class Pattern1
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        System.out.println("Enter a String");
        String s=in.nextLine();
        int i,j; 
        
        for(i=0;i<=s.length()-1;i++)
        {
            for(j=0;j<=i;j++)
            System.out.print(s.charAt(j));
            System.out.println();
        }
        
    }
}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...