Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DiamondSingleFor {
- public static void main(String[] args) {
- System.out.print("Masukan Input : ");
- Scanner input=new Scanner(System.in);
- int a;
- a=input.nextInt();
- int b=1;
- int c=a;
- a=(a+(a-1));
- c=a-c;
- int d=1;
- int f=0;
- for(int e=0;e<a;){
- if(c>=0){
- if(b<=c)
- System.out.print(" ");
- else if(f<d){
- System.out.print("*");
- f++;
- }
- else{
- d+=2;
- c--;
- System.out.println();
- b=0;
- f=0;
- e++;
- }
- b++;
- }
- else if(c==-1){
- d-=4;
- c--;
- b=-1;
- }
- else{
- if(b>c)
- System.out.print(" ");
- else if(f<d){
- System.out.print("*");
- f++;
- }
- else{
- d-=2;
- c--;
- System.out.println();
- b=0;
- f=0;
- e++;
- }
- b--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement