Results 1 to 12 of 12
  1. #1
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Question How to Print out adiamond pattern I try this code but

    How to Print out adiamond pattern I try this code but it print out one Line
    Java Code:
    import java.util.*;
    
    public class Main {
     static Scanner  console = new Scanner(System.in);
        public static void main(String[] args)
        { 
         int numberofbalanks;    
         int counter;
         int count; 
         numberofbalanks =30;
         for(counter=1;counter<=6;counter++)
         {
          
         for(count=1;count<=blanks;count++)
         System.out.print("");
         for(count=1;count<=starsinline;count++)
         System.out.print("*");    
         System.out.println();
         }
         for(counter=5;counter>=0;counter--)
         {
            
         for(count=1;count<=blanks;count++)
         System.out.print("");
         for(count=1;count<=starsinline;count++)
         System.out.print("*");    
         System.out.println();
         }
                
        }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You should given a full code or compilable code here to test. I don't have an idea about few variables you used, like blanks and so on.

    And also here in the following code, why did you do this.

    Java Code:
         int numberofbalanks;    
         numberofbalanks =30;
    Actually pal no need to use two lines for this.

    Java Code:
         int numberofbalanks = 30;

  3. #3
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default


    Please post ....output that you want.


    sanjeev

  4. #4
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Thumbs up

    the image with attachment
    Attached Thumbnails Attached Thumbnails How to Print out adiamond pattern I try this code but-untitled.jpg  
    Last edited by masaka; 04-16-2008 at 11:03 AM.

  5. #5
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Hello,


    Try This..for output you given last time

    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *


    Java Code:
    public class PrintStar 
    {
    	public static void main(String[] args){
    		printStars();		
    	}
    
    	public static void printStars(){
    		int k = 5;
    		for (int i=0;i<9 ;i++ ){
    			if(i<5){
    				for (int j=0;j<=i;j++ ){
    					System.out.print("*");
    				}
    			}else{
    				for (int j=0;j<=k-2;j++ ){
    					System.out.print("*");
    				}
    				k--;
    			}
    			System.out.println();
    		}
    	}
    }

    sanjeev

  6. #6
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

    Default

    Please check The image

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Ah, you have change the image. So try it with Sanjeev code. Actually you have to deal with some spaces there.

  9. #9
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default


    Ya, you have changed the image.
    anyway i thing you can change in my code as per your requirements.


    sanjeev

  10. #10
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    THis could be done by having first an experiment on it....
    write it, predict, code it, and realize....

    Not on a hurry,
    sukatoa

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  12. #12
    masaka is offline Member
    Join Date
    Mar 2008
    Posts
    31
    Rep Power
    0

Similar Threads

  1. Strategy Pattern
    By mew in forum New To Java
    Replies: 0
    Last Post: 01-25-2008, 08:34 PM
  2. Singleton Pattern
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-24-2008, 04:21 PM
  3. Using Pattern.CASE_INSENSITIVE
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 11:45 AM
  4. Regex pattern
    By ravian in forum New To Java
    Replies: 4
    Last Post: 12-11-2007, 11:20 AM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

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