Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how can u make a triangle

  Asked By: Juana    Date: Nov 16    Category: Java    Views: 1906
  

i need help desperately on this qn...




how can u make a triangle like this:




000000000000000


11111111111111


2222222222222


333333333333


44444444444


5555555555


666666666


77777777


8888888


999999


00000


1111


222


33


4




the length and height is 15... and the program should be able to
handle values of 100... the length is defined by the user... thankz in
advance...

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Adalric Fischer     Answered On: Nov 16

is this your homework ?
try it first by yourself, if you got problems, send us your codes to this
mailing list.
This homework is not difficult to solve ... :)

just a hint, learn about looping in Java ..

 
Answer #2    Answered By: Julia Flores     Answered On: Nov 16

This is a simple programming problem. Look into mod (MODUDLUS) operations,
and use mod 10. (Should be Math.mod - checkout the Math class).

 
Answer #3    Answered By: Jarvia Miller     Answered On: Nov 16

x modulo n is eq. in Java with x%n
Ovidiu Pitic

 
Answer #4    Answered By: Allan Bailey     Answered On: Nov 16

Here is the code for that:

class NumberTriangle
{
public static void main(String[] args)
{
int i, j=0, k=0;
while(k<=15){
for(i=0;i<=k;i++)
{
System.out.print(" ");
}
for(i=0;i<=15-k;i++)
{
System.out.print(j+" ");
}
System.out.println();
k++;
j++;
if(j>9)
j=0;
}
}

}

 
Answer #5    Answered By: Baylen Smith     Answered On: Nov 16

As a university "Intro to Computer Science" instructor, I believe that you
just did someone's homework for them. I can only hope that they learn
enought to be able to create this code correctly on the midterm in a couple
of weeks.

 
Answer #6    Answered By: Lughaidh Fischer     Answered On: Nov 16

as a student you shouldnt ask... and if you do and dont understand
the answer, you shouldnt pass ... life is selfregulating, thats my firm
belief

 
Answer #7    Answered By: Aalia Arain     Answered On: Nov 16

I dont know if you are one of the "help me get a triangle  output" guys...
if not i dont think my comment regards you. ;o)

I dont know how university works in other parts of the world, but being a
university student myself in sweden I have seen that there is a lot of
tutoring going on... and that this rather than the lecture is what will
teach us programming...

Programming is that kind of subject that (like for instance mathematics)
wont go in undless you write code-write code-write code... hehehe...

Well, so when i see people comming here asking how to print out a triangle
i can only assume they (and their college?) are in deep deep trouble...
ehhh... okay maybe harsh but... we cannot be the instructors for a
university... maybe we should start a java-uni list on here and send all
triangles there? (and maybe with some persuasion we may get the uni
instructors to join it as well? ;o)

But surely, you people with the triangles... don't you have tutoring?

 
Didn't find what you were looking for? Find more on how can u make a triangle Or get search suggestion and latest updates.




Tagged: