473,796 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inverting the Triangle using the java for loops

1 New Member
My homework this week involved using the for statement to create loops that would display triangles. The only output we're allowed to use are forms of the print statements... i.e. print(), println(). I've gotten my code to display the first 2 triangles I need, but I cannot manage to "invert" the triangles for the second part...

I need to create code that will make a triangle look like V

*********
*******
*****
***
**
*
using ( ' ' ) to produce x number of spaces before displaying the asterisks. my code for my working Triangle is
Expand|Select|Wrap|Line Numbers
  1.  public class Triangle 
  2.  
  3. {
  4.  
  5.         public static void main( String[] args ) {
  6.  
  7.         for( int x=0; x<=10; x++ )
  8.             {
  9.             for( int y=10; y>=x; y-- ) {
  10.                 System.out.print( "*" );
  11.                 }
  12.  
  13.             System.out.println( "" );
  14.         }
  15.     }
  16. }
  17.  
If someone could just help me get it turned around the right way I would appreciate it very very much.
Mar 9 '07 #1
1 9802
r035198x
13,262 MVP
My homework this week involved using the for statement to create loops that would display triangles. The only output we're allowed to use are forms of the print statements... i.e. print(), println(). I've gotten my code to display the first 2 triangles I need, but I cannot manage to "invert" the triangles for the second part...

I need to create code that will make a triangle look like V

*********
*******
*****
***
**
*
using ( ' ' ) to produce x number of spaces before displaying the asterisks. my code for my working Triangle is
Expand|Select|Wrap|Line Numbers
  1. public class Triangle 
  2.  
  3. {
  4.  
  5.      public static void main( String[] args ) {
  6.  
  7. for( int x=0; x<=10; x++ )
  8.     {
  9. for( int y=10; y>=x; y-- ) {
  10. System.out.print( "*" );
  11. }
  12.  
  13. System.out.println( "" );
  14. }
  15. }
  16. }
  17.  
If someone could just help me get it turned around the right way I would appreciate it very very much.


Expand|Select|Wrap|Line Numbers
  1.  
  2. int spaces = 0;
  3.   int starsNum = 10;
  4.   String stars = "***********";
  5.   for( int x = 0; x < starsNum; x++) {
  6.    for(int i = 0; i < spaces; i++) {
  7.     //print spaces
  8.    }
  9.    //print stars
  10.    //remove 2 stars from the strng stars
  11.    //increment stars by 1
  12.   }
  13.  
Mar 10 '07 #2

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

Similar topics

2
5173
by: webstar | last post by:
How do you play wave files using java.applet.Applet?
1
4337
by: ochulus | last post by:
Hi! I'm new to Java and I would like to know how to manage files (e.g. rm, mv, mkdir, etc.) using Java for a simple text-based application on Unix. It's just an extension of a tutorial question at uni where we have to store bank customer details to a file. Thank you! pras
1
2509
by: Utada P.W. SIU | last post by:
Hi all professional I would like to know how to using java class file inside ASP page I have placed the class file to C:\WINNT\java\trustlib also, I have compiled it to 1.1 version but it always prompt error '800401e5' No object for moniker
10
1957
by: asj | last post by:
BIG news from the web services front. Amazon will use web services to tie all its vendors together. The company implementing the system will be using Java/C++ (migrating to all-java later). Isn't it funny how Microsoft spent so much touting .NET for web services, and J2EE is actually taking a bigger slice of the pie? http://www.internetnews.com/ec-news/article.php/3077221
2
9246
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
4
1371
by: ray2007colon | last post by:
Hi, I have a confusion with java loops, I’m a student and I don’t understand how after you are at the end of the program loop back to the middle, to do a step again. I don’t understand where to put the loop. I tried, while, do while and if else, but I’m very confuse. Please help.
6
13367
by: jackj | last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a triangle that aligns to the left of the screen, but it loops and disappears immediately. So, my problem is getting it to stay on the screen and then ask the user if they want to create another one AND to make it print the first symbol in the center of...
1
1459
by: aishswami | last post by:
Hi i face trouble in comparing two dates in loop using java scripts... give me suggestion abt the problem...
1
3931
by: Shun | last post by:
Hello, I am trying to extract the data from my Oracle 10g database using Java. First, I tried to connect Oracle to Java using this code and it works. import java.util.*; import java.sql.*; import java.io.*; public class TestDBOracle {
0
10453
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.