Hello! I have to print patterns using '*' and I am at a loss how to get these patterns printed!

I figured out the first one,
*
**
***
****
*****
******
*******
********
*********
**********

and now i have to do it upside down:
**********
*********
********
*******
******
*****
****
***
**
*

and backwards:
**********
_*********
__********
___*******
____******
_____*****
______****
_______***
________**
_________*
and

_________*
________**
_______***
______****
_____*****
____******
___*******
__********
_*********
**********

this is the code i have for the first one:

for (int i =0; i < 10; i++)
        {
            for (int j=0; j < i+1; j++)
            {
                System.out.print('*');
            }
            System.out.println();
        }

and I figured if I just changed the numbers around and made i go from 10 to zero it would print out but it is not working. any help??? please!!

Thanks!

Hello! I have to print patterns using '*' and I am at a lose how to get these patterns printed!

I figured out the first one,
*
**
***
****
*****
******
*******
********
*********
**********

and now i have to do it upside down:
**********
*********
********
*******
******
*****
****
***
**
*

and backwards:
**********
*********
********
*******
******
*****
****
***
**
*
and

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

this is the code i have for the first one:

for (int i =0; i < 10; i++)
        {
            for (int j=0; j < i+1; j++)
            {
                System.out.print('*');
            }
            System.out.println();
        }

and I figured if I just changed the numbers around and made i go from 10 to zero it would print out but it is not working. any help??? please!!

Thanks!

wouldnt you have to swap the loops around too? or maybe the sign from +->- or both. Havent tested just thinking logically now

commented: trying to race me? :) +14

actually, yes. but you also have to change the +'s to -'s, and < to >.
can you show the changed code you tried?

actually, yes. but you also have to change the +'s to -'s, and < to >.
can you show the changed code you tried?

for(int k = 10; k > 0; k--){
            for(int l=10; l > k; l--){
                System.out.print('*');
            }
            System.out.println();
        }

however this gives me exactly what I get in part a.

for(int k = 10; k > 0; k--){
            for(int l=10; l > k; l--){
                System.out.print('*');
            }
            System.out.println();
        }

however this gives me exactly what I get in part a.

where is the -1 you had going in the original algorithm ?

you don't have to completely turn around the inner for loop.
and, in that for loop, you don't need to compare it to '10' but to the value of 'k'

where is the -1 you had going in the original algorithm ?

I have it there now and still does the same as the first one!

you don't have to completely turn around the inner for loop.
and, in that for loop, you don't need to compare it to '10' but to the value of 'k'

What do you mean? Could you put it in code for me?
[EDIT!]

I got it! Now am just working on the backwards ones!

the backward ones are just those two you already have printed right after each other.
you already have the code, just make sure its re-usable

the backward ones are just those two you already have printed right after each other.
you already have the code, just make sure its re-usable

I got part c but it is not aligned correctly....

I got part c but it is not aligned correctly....

how is it not aligned? can you show the algorithm?

part c? what is part c?
in this backwards you have to decide what to print
at first: the number of spaces, then the number of *'s
and this for each line

find a pattern to print this shape, and write the code for it

Member Avatar for hfx642

For your second attempt... Try a regular ascending loop from 1 to K.

Sorry... I posted before reading stultuske's post.

how is it not aligned? can you show the algorithm?

I thought of asking that too, but in this thread, his backwards is different from in the other thread :)

I thought of asking that too, but in this thread, his backwards is different from in the other thread :)

the different parts a, b, c and d are the four different patterns that needed to be printed. in the end I figured out this code:

public static void problem7(){
        System.out.println("Part a)");
        for (int i =0; i < 10; i++)
        {
            for (int j=0; j < i+1; j++)
            {
                System.out.print('*');
            }
            System.out.println();
        }
        System.out.println("Part b)");
        for(int k = 10; k > 0; k--){
            for(int l=0; l < k-1; l++){
                System.out.print('*');
            }
            System.out.println();
        }
        System.out.println("Part c)");
        for(int k = 10; k > 0; k--){
            for(int l=0; l < k-1; l++){
                System.out.print(' ');
            }
            for(int n=10; n > k-1; n--){
                System.out.print('*');
            }
            System.out.println();
        }
        System.out.println("Part d)");
        for(int k = 0; k < 10; k++){
            for(int l=1; l < k+1; l++){
                System.out.print(' ');
            }
            for(int n=10; n > k; n--){
                System.out.print('*');
            }
            System.out.println();
        } 
    }

and as for the diamond thread which was a whole different problem, I got this code:

public static void problem8(){
        Scanner input = new Scanner(System.in);  
        System.out.println("Input odd number ");
        String number = input.nextLine();
        int n = Integer.parseInt(number);
        for (int i = 1; i < n+1; i +=2) {
            for (int j = 0; j < n-i / 2; j++)
                System.out.print(" ");
            for (int j = 0; j < i; j++)
                System.out.print("*");
            System.out.print("\n");
        }
        for (int i = n-2; i > 0; i -= 2) {
            for (int j = 0; j < n - i/2; j++)
                System.out.print(" ");
            for (int j = 0; j < i; j++)
                System.out.print("*");
            System.out.print("\n");
        }
    }

I'm sorry if I was a little confusing! I had no background in this type of outputting before receiving these problems. But thank you all for your help, I figured it out :)

can u make -> pattern in stars and various other tyeps of pattern

Yes you can, IF you learn to program and take the time to think through how to do it.
If you would like help with either of those please start your own thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.