473,396 Members | 1,714 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,396 software developers and data experts.

Need help on Looping

I am trying to write a program for an assignment that uses a For loop to produce an output that looks like this:

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

I started writing a code but i'm not sure how for example on the first triangle to increment 1 "*" on each new line. Can someone help me on incrementing 1 "*" on each of the next 10 lines to get the triangle pattern? Than I should be able to get the next 3 triangles. Thanks for your help.
[code]
public class Triangle
{
public static void main( String args [] )
{
for ( int j = 1; j <= 10; j ++ )
{
for ( int i = 1; i <= 10; i ++)
System.out.print ( '*');
System.out.println();
}
}
}

Output:
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
Press any key to continue . . .
Nov 14 '06 #1
1 1209
Velhari
46
I am trying to write a program for an assignment that uses a For loop to produce an output that looks like this:

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

I started writing a code but i'm not sure how for example on the first triangle to increment 1 "*" on each new line. Can someone help me on incrementing 1 "*" on each of the next 10 lines to get the triangle pattern? Than I should be able to get the next 3 triangles. Thanks for your help.
[code]
public class Triangle
{
public static void main( String args [] )
{
for ( int j = 1; j <= 10; j ++ )
{
for ( int i = 1; i <= 10; i ++)
System.out.print ( '*');
System.out.println();
}
}
}

Output:
**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
Press any key to continue . . .
Hi,
I think the following code will hopefull to you................
[code]
public class Triangle
{
public static void main(String args[])
{
int k=1;
int m=10;
while ( k!=10 && m!=1 )
{
for ( int i=1; i<=k; i++ )
{
System.out.print ("*");
}
System.out.print(" ");
for ( int i=1; i<=m; i++ )
{
System.out.print ("*");
}
System.out.print (" ");
for ( int i=1; i<=m; i++ )
{
System.out.print ("*");
}
System.out.print (" ");
for ( int i=1; i<=k; i++ )
{
System.out.print ("*");
}
System.out.println();
k++;
m--;
}
}
}
Nov 14 '06 #2

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

Similar topics

5
by: masood.iqbal | last post by:
My simplistic mind tells me that having local variables within looping constructs is a bad idea. The reason is that these variables are created during the beginning of an iteration and deleted at...
2
by: RCB | last post by:
I created a new Vb.NET project and used the Data Form Wizard to create a dataset and grid to view a single table from my database. Later I read an article about creating a Typed Dataset. I was...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
43
by: SLH | last post by:
hi people. im trying to validate input received via a text area on an ASP page before writing it to a database. i cant use client side javascript due to policy, so it all has to happen on the...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
1
by: darrel | last post by:
Hi vb master i need help on this here my code: If Combo1(0) = rs.Fields("TimeStart") And Combo4(0) = rs.Fields("TimeEnd") And Combo2(0) = rs.Fields("ROOM") And Combo3(0) = rs.Fields("DAYS")...
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
2
by: Davaa | last post by:
Dear all, I am a student making a MS Form application in C++. I would ask a question about "Timer". Sample code which I am developing is below. private: System::Void...
1
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.