473,396 Members | 1,864 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.

Inverting the Triangle using the java for loops

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 9779
r035198x
13,262 8TB
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
by: webstar | last post by:
How do you play wave files using java.applet.Applet?
1
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...
1
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...
10
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). ...
2
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...
4
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...
6
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...
1
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
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.*;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...
0
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.