473,387 Members | 1,585 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.

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 9777
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.