This is intented for learning purposes, feel free to study the code

Create a drawing that looks like this (pyramid)
The number should be incremented with the modulus.

Edited 2 Years Ago by Szabi Zsoldos

1.simple version
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    ***********
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    
    2. modulus with array
    *
    ***
    *****
    *******
    *********
    **********
    *********
    *******
    *****
    ***
    *


    import java.util.ArrayList;
    import java.util.List;
    
    
    public class pyramidDrawing {
    
    	public static void main(String[] args) {
    		
    		simpleDrawing(10);
    		arrayDrawing(10);
    		
    	}
    	
    	
    	public static void simpleDrawing(int number) {
    		for(int i = 1; i <= number; i++) {
    			for(int j = 1; j <= i; j++) {
    				System.out.print("*");
    			}
    			System.out.println();			
    		}
    		
    		for(int x = 1; x <= (number+1) ; x++) {
    			System.out.print("*");
    		}
    		System.out.println();		
    		
    		for(int v = number; v >= 1; v--) {
    			for(int q = 1; q <= v; q++) {
    				System.out.print("*");
    			}
    			System.out.println();			
    		}		
    	}
    	
    	
    	public static void arrayDrawing(int number) {
    		List<Integer> numbers = new ArrayList<Integer>();
    		
    		for(int num = 1 ; num <= number; num++) {
    			numbers.add(num);
    		}
    		
    		for(int i = 0; i < numbers.size(); i++) {
    			if(i % 2 == 0) {
    				for(int j = 0; j <= i; j++) {
    					System.out.print("*");
    				}
    				System.out.println();
    			}
    		}
    		
    		for(int x = 1; x <= (numbers.size()) ; x++) {
    			System.out.print("*");
    		}
    		System.out.println();
    		
    		for(int v = numbers.size(); v >= 0; v--) {
    			if(v % 2 != 0) {
    				for(int q = 1; q <= v; q++) {
    					System.out.print("*");
    				}
    				System.out.println();
    			}
    		}		
    	}
    }

is there an actual question here, or is it just meant to be a 'how-to' post?

Edited 2 Years Ago by stultuske

Then you should not posted at all because if they never learn basic they will fail. It is OK to help with attempt when someone tried and got catch in some circumstances that may not be obvious. However provide solution beforehand is plain bad.

WARNING: To anyone copying code for a homework assignments:
Your teacher can probably spot solutions copied from the web. If so you will get 0 marks, and may be penalised for cheating. YOu are also wasting your own time by cheating instead of learning. Write your own code!

Szabi: I'm sure your intentions were good, but in this forum we always perfer to teach people how to write good code. Your code may be a valid solution to the requirement, but in terms of commenting and clarity it's not a good example for a beginner, and not easy to learn from. Posts that just give solutions without explanations tend to pick up a lot of down-votes.

snippets is fine, but entire solutions to common homework problems is not.

For example the following is helpful to a lot of people in real situations, but useless to a schoolkid trying to get away with not doing his homework:

String requestUri = request.getRequestURI();
StringBuffer requestURL = request.getRequestURL();
requestURL.delete(requestURL.length()-requestUri.length(), requestURL.length()+1);
requestURL.append(request.getContextPath());
This question has already been answered. Start a new discussion instead.