Monday 24 August 2020

T

#Program to Print alphabet 'T' in Star Pattern

Expected Output:

* * * * *

     *  

     *  

     *  

Code in Java: 
public class Tpattern 
{
	void T()
	 {
		for(int i=1; i<=5; i++)//Outer loop for number of rows
		{
			for(int j=1; j<=5;j++)//inner loop for number of columns
			{
				//if condition to print the T pattern Stars
					if(i==1 || j==3)
					{
					System.out.print("*");//printing stars
					}
					else
					{
					System.out.print(" ");//for white spaces
					}
				}System.out.println();
			}System.out.println();//printing newline after each row
	 }
	public static void main(String[] args) 
    {
		Tpattern obj=new Tpattern();
		obj.T();
	}
}    


No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32