Results 1 to 9 of 9

Thread: Write A Program Code In Java To Print Cross Pattern

  1. #1

    Write A Program Code In Java To Print Cross Pattern

    * *
    * *
    * *
    *
    * *
    * *
    * *
    Code:
    class Cross
    {
    public static void main(String args[])
    {
    int i, j,k;
     for(k=0;k<5;k++)
     { 
         for(j=0;j<k;j++)
    System.out.print(" ");
    System.out.print("*");
    
       for(i=j+1;i<(9-k);i++)
    System.out.print(" ");
     System.out.print("*");
    System.out.println();
    }
    }
    }
    techforum4u.com Member!!

  2. #2

    Re: Write A Program Code In Java To Print Cross Pattern

    i am not able to print a cross pattern please help me. code is ryt but.
    techforum4u.com Member!!

  3. #3

    Re: Write A Program Code In Java To Print Cross Pattern

    nice work chikoo sir. its really a good program and we expect more from you.
    techforum4u.com Member!!

  4. #4
    Administrator Harsh's Avatar
    Join Date
    May 2010
    Posts
    567
    Blog Entries
    92
    Rep Power
    10

    Re: Write A Program Code In Java To Print Cross Pattern

    Quote Originally Posted by chikoo View Post
    i am not able to print a cross pattern please help me. code is ryt but.
    Can u use an image of the pattern for better understanding?
    " Don't limit your challenges, challenge your limits "
    (Harsh Chowdhary)

  5. #5
    Super Moderator angad's Avatar
    Join Date
    Aug 2010
    Location
    nature
    Posts
    505
    Blog Entries
    132
    Rep Power
    4

    Re: Write A Program Code In Java To Print Cross Pattern

    You can also give the link to the image. that will also do.
    techforum4u.com Member!!

  6. #6
    Moderator goldsonam's Avatar
    Join Date
    Feb 2011
    Location
    India
    Posts
    183
    Blog Entries
    20
    Rep Power
    4

    Re: Write A Program Code In Java To Print Cross Pattern

    Unable to make out what exactly you want to print! is it "X"?
    techforum4u.com Member!!

  7. #7
    Super Moderator angad's Avatar
    Join Date
    Aug 2010
    Location
    nature
    Posts
    505
    Blog Entries
    132
    Rep Power
    4

    Re: Write A Program Code In Java To Print Cross Pattern

    ya golsonam. i too think its X not +? because we sometime takes jesus divine symbol as cross too. but here i guess its X pattern
    techforum4u.com Member!!

  8. #8
    Moderator goldsonam's Avatar
    Join Date
    Feb 2011
    Location
    India
    Posts
    183
    Blog Entries
    20
    Rep Power
    4

    Re: Write A Program Code In Java To Print Cross Pattern

    Chikoo,

    what your code is printing is "V" and not "X"..you have missed the last part for printing the lower ^ of the "X" pattern...hence you are not getting the output!
    techforum4u.com Member!!

  9. #9
    Moderator goldsonam's Avatar
    Join Date
    Feb 2011
    Location
    India
    Posts
    183
    Blog Entries
    20
    Rep Power
    4

    Re: Write A Program Code In Java To Print Cross Pattern

    Try this out.....
    Code:
    class Cross
    {
    public static void main(String args[])
    {
    int i, j,k;
     for(k=0;k<5;k++)
     { 
         for(j=0;j<k;j++)
    System.out.print(" ");
    System.out.print("*");
    
       for(i=j+1;i<(9-k);i++)
    System.out.print(" ");
     System.out.print("*");
    System.out.println();
    }
    
    for(k=0;k<5;k++)
     {
        for(l=1; l<5-k; l++)
        System.out.print(" ");
    
       System.out.print("*");
    
    for(i=0;i<(2*k);i++)
    System.out.print(" ");
    
    System.out.print("*");
    }
    }
    }
    techforum4u.com Member!!

Similar Threads

  1. Replies: 0
    Last Post: 10-31-2011, 05:30 PM
  2. Write A Program Code in Shell Script to print the following Pattern :
    By VIBHAVARI KULKARNI in forum Shell Script
    Replies: 0
    Last Post: 10-29-2011, 07:31 PM
  3. Replies: 2
    Last Post: 03-18-2011, 01:33 PM
  4. Replies: 1
    Last Post: 03-18-2011, 09:43 AM
  5. Write A Program In Java To Print The Pattern
    By cseradh in forum JAVA SE
    Replies: 0
    Last Post: 02-14-2011, 06:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.