473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help with program

How would I make a java program using for loops to print the following pattern...

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

i started it but dont know what to do...

public class Stars
{
public static void main (String []args)
{
final int MAX_ROWS=10;
for (int row=1; row<=MAX_ROWS; row++)
{

.....
Oct 21 '06 #1
1 1340
r035198x
13,262 8TB
How would I make a java program using for loops to print the following pattern...

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

i started it but dont know what to do...

public class Stars
{
public static void main (String []args)
{
final int MAX_ROWS=10;
for (int row=1; row<=MAX_ROWS; row++)
{

.....
Never under-estimate the power of the "growing phase-shrinking phase approach"

Expand|Select|Wrap|Line Numbers
  1. public class Stars {
  2.     public static void main (String []args) {
  3.         final int MAX_ROWS = 9;
  4.         int n = 6;
  5.         String stars = "*";
  6.         for (int row=0; row < MAX_ROWS; row++) {
  7.             for(int i = 0; i < n;i++) {
  8.                 System.out.print(" ");
  9.             }
  10.             System.out.println(stars);
  11.  
  12.             if(row >= 4) {
  13.                 if(stars.length() == 1) {
  14.                     break;
  15.                 }
  16.                 n++;
  17.                 if(row == 9) {
  18.  
  19.                 }
  20.                 else {
  21.                     stars = stars.substring(0, stars.length()-2);
  22.  
  23.                 }
  24.             }
  25.             else {
  26.                 n--;
  27.                 stars = stars + "**";
  28.             }
  29.         System.out.println();
  30.         }
  31.     }
Oct 23 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
8
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'd like to write a program to assist me in upoloading files to my site. I know how to upload the files using C#, I just don't know how to have an interface and still accept commandline parameters. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.