sign in • sign up
web | myLot | discussions | tasks | blogs | news | photos
homeinterestsdiscussionstasksblogsnewsmessages friendsphotosearningsmyLotquizzes

Help me with java email this discussion to a friend?

myLot reputation of 82/100. Pinimo (316)   ranked 40 out of 131 in java3 years ago

I am a freshman computer science student and one of my new subject is java programming. We were ask to make a diamond program using for loop and the diamond should be made of (*). I write a diamond program, though its correct, my instructor told me to simplify this using other method. Please Help Me! many tnx to you!
This is my program:
//Diamond program
public class Diamond{
public static void main(String[] args){

for (int a=1; a<6; a++){
System.out.print(" ");

for (int a=1; a<6; a++){
System.out.print(" ");
for (int c=a; c>=1; c--)
System.out.print("*");
for (int c=2; c<=a; c++)
System.out.print("*");
System.out.println();
}
for (int d=4; d>=1; d--){
for(int e=6; e>=1+d; e--)
System.out.print(" ");
for( int f=d; f>=1; f--)
System.out.print("*");
for(int f=2; f<=d; f++)
System.out.print("*");
System.out.println();
}
}
}//end


java
 
 
java
User has not selected a best response.
tags:  java, java program, bellaonlinecom
 
1. inhefyh (64)   3 years ago

I copy your program to a notepad. I found you lose a} in
your program. I'm a java beginner too.

 
2. muralikrishna88 (99)   ranked 80 out of 131 in java   3 years ago

This is a generic program for any diamond size. All you have to do is to change the size of N. As a demo I have used n as 5. You can change it.

// inside the main method

int n=5;

for(int i=n; i>=1; i--)
{
for(int x=0; x<(i-1);x++)
{
System.out.print(" ");
}
for(int y=n; y>=i; y--)
{
System.out.print("* ");
}
}
for(int i=2; i<= n; i++)
{
for(int x=0; x< (i-1); x++)
{
System.out.println(" ");
}
for(int y=n; y>=i; y--)
{
System.out.print("* ");
}
}

 
3. julieandpico (57)   ranked 83 out of 131 in java   3 years ago

What a fun problem! You inspired me to use this for my weekly column at BellaOnline.com. You can read my comments and see my answer here - "Fun With Java - Draw A Diamond" http://www.bellaonline.com/articles/art40020.asp

I also asked other people for their suggestions, so maybe we'll get some even simpler answers.

Thanks!

 
sponsors
Int'l Acad. of Design and Tech
Information on International Academy of Design and Technology.
www.StateUniversity.com

Washington Nationals Tickets
Buy premium Washington Nationals tickets securely - book online 24/7.
www.frontrowseatsllc.com

WA Appraiser Class
Become A Real Estate Appraiser Now Quick& Easy Home Study Courses.
www.RealEstateLicense.com

similar discussions
Do you like drink your coffee from small cup or cup?
Do you prefear to drink just one cup in one day, a big one, or like to drink 3,4 small cups of...
Java getting overshadowed by other programming languages
Do you think that java is getting overshadowed by other new languages. I mean are newer languages a...
Visual Basic Or Java?
do you know about programming language? here im study visual basic. but many people say Java better...
return to mylot
We are loading a word from our sponsors. No thanks, cancel loading.