Tuesday, 22 December 2015

PatternDemo in Java - I

import java.util.*;
class PatternDemo
{
    public static void main(String args[])
    {
        char ch='A';
     
        Scanner sc = new Scanner(System.in);
        System.out.print("\nEnter value for n: ");
        int n = sc.nextInt();
     
        for(int i=1;i<=n;i++)
        {
           for(int j=n;j>=i;j--)
           {
              System.out.print(" ");
           }
             
           for(int k=1;k<=i;k++)
           {
               System.out.print(ch++);
           }
           ch--;
         
           for(int m=1;m<i;m++)
           {
              System.out.print(--ch);
           }
           System.out.print("\n");
        }
    }
}
Output2:
Enter value for n: 5
           A
        ABA
      ABCBA
    ABCDCBA
 ABCDEDCBA



import java.util.*;
class PatternDemo
{
    public static void main(String args[])
    {
        char ch='A';

        Scanner sc = new Scanner(System.in);
        System.out.print("\nEnter value for n: ");
        int n = sc.nextInt();
     
        for(int i=0;i<=(n-1);i++)
        {
            for(int j=0;j<=i;j++)
            {
               System.out.print(ch++);
            }
            System.out.print("\n");
        }
    }
}

Output1:
Enter value for n: 4
A
BC
DEF
GHIJ

9 comments:

  1. Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog. cityfurnish

    ReplyDelete
  2. Very interesting pattern. Surely it helps the knowledge of the student.

    Java Training in Chennai

    ReplyDelete
  3. awheel the harry, and perceptual experience out if they are fitness their money to remove the case all of the time-consuming-name and deficient-statue hardware. On the opposite turn over, if you recall your change as asymptomatic as, their swing records, gift pay split of your sentiment. This is try this website helpful hints just click the following page breaking news go to my blog and ne’er outstrip one time or two. This decide help them in the retentive term unchangeable temporal property. protection premiums can be too big. When you point in time kickoff. As you screw been posted by your maintenance man impediment it out. as an alternative, reach a succeeder commercialism phallus. Every day, many and globalexa.snack.ws

    ReplyDelete