Please help.
i do not know how to do this as i am a java beginner. i only know to use a string and output.
how do i do this with a loop?
this shows to the side bit it should be in the middle.... like an upside down A .. like the letter V filled with stars

****
***
**
*

please help!

Recommended Answers

All 4 Replies

System.out.println("Enter Number of rows you want.");
        Scanner br = new Scanner(System.in);
        int num = br.nextInt();
        for(int i=0;i<num;i++)
        {
            for(int j=0;j<i;j++)
                System.out.print(" ");
            for(int j=0;j<(2*(num-i)-1);j++)
                System.out.print("*");
            System.out.println();
        }

scanner seems too complex. pls let me know how to do it in the simplest form.

Scanner is a class that provides you with some functions such as getting the input from user.You can just use
"int num=Integer.ParseInt(args[0])",which gets the first input from the command line when you run your program.If you just dont want to get the input from the user,you can just simply put "num=any number"

scanner seems too complex. pls let me know how to do it in the simplest form.

Scanner is just to take the input from the user the no of lines required. If you want it to do in a simple way without scanner you can fix the no of lines such as 5.

int num = 5;//No of Lines
        for(int i=0;i<num;i++)
        {
            for(int j=0;j<i;j++)
                System.out.print(" "); 
            for(int j=0;j<(2*(num-i)-1);j++)
                System.out.print("*");
            System.out.println();
        }
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.