Help me with java  | | 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 |
|
| |
| | | | | | | | | 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) | 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) | 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!
| |
| |
|
| | | | | | | |
| Visual Basic Or Java? do you know about programming language? here im study visual basic. but many people say Java better... | |
|
|
|
|
|