Designing Patterns - Print 'Y'.

SOURCE CODE

import java.io.*;
import java.util.*;
public class Y
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner (System.in);
        System.out.print("Enter a odd number >=5 :");
        int n=sc.nextInt();
        int a=n/2+1,k5=n;
        System.out.println("\n");
        if(n>=5&& n%2!=0 )           
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if((i==j && i<=a)|| (j==a)&& i>=a || (j==k5 && j<=k5 && i<a))
                        System.out.print("Y ");
                    else
                        System.out.print(" ");
                }
                k5--;
                System.out.println();
            }
        }
        else
        System.out.println("Invalid Input.");
    }
}

OUTPUT






If you have any question then leave a comment below I will do my best to answer that question.




Comments

Popular posts from this blog

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

Pattern of your own name.

Designing Patterns - Print 'Z'.