Advertisement
akevintg

DIAMOND using Single For

Oct 4th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.        
  3. public class DiamondSingleFor {
  4.  
  5.     public static void main(String[] args) {
  6.         System.out.print("Masukan Input : ");
  7.         Scanner input=new Scanner(System.in);
  8.         int a;
  9.         a=input.nextInt();
  10.         int b=1;
  11.         int c=a;
  12.         a=(a+(a-1));
  13.         c=a-c;
  14.         int d=1;
  15.         int f=0;
  16.         for(int e=0;e<a;){
  17.             if(c>=0){
  18.                 if(b<=c)
  19.                     System.out.print(" ");
  20.                 else if(f<d){
  21.                     System.out.print("*");
  22.                     f++;
  23.                 }
  24.                 else{
  25.                     d+=2;
  26.                     c--;
  27.                     System.out.println();
  28.                     b=0;
  29.                     f=0;
  30.                     e++;
  31.                 }
  32.                 b++;
  33.             }
  34.             else if(c==-1){
  35.                 d-=4;
  36.                 c--;
  37.                 b=-1;
  38.             }
  39.             else{
  40.                 if(b>c)
  41.                     System.out.print(" ");
  42.                 else if(f<d){
  43.                     System.out.print("*");
  44.                     f++;
  45.                 }
  46.                 else{
  47.                     d-=2;
  48.                     c--;
  49.                     System.out.println();
  50.                     b=0;
  51.                     f=0;
  52.                     e++;
  53.                 }
  54.                 b--;
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement