Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.          
  3.     public class Testoo
  4.     {    
  5.             private static Scanner keyboard;
  6.             static int number = 0;
  7.            
  8.             public static void main(String[] args)
  9.             {                    
  10.                     keyboard = new Scanner(System.in);
  11.  
  12.                     while(true)                
  13.                     {
  14.                     System.out.println("Enter the amouth of lines you want to your diamond: ");
  15.                     String d = keyboard.nextLine();
  16.                     if(Terve(d) == true)
  17.                     {
  18.                         number = Integer.parseInt(d);
  19.                         d= "";
  20.                     for(int x = 1; x <= number; x=x+2)
  21.                     {
  22.                             for (int y = 0; y < (number - x / 2); y++)
  23.                               System.out.print(" ");
  24.      
  25.                             for (int y = 0; y < x; y++)
  26.                               System.out.print("*");
  27.                            
  28.                             System.out.println();
  29.                     }
  30.                     if (number%2==0)
  31.                     {
  32.                     for(int x = number-1; x > 0; x=x-2)
  33.                     {
  34.                                 for (int y = 0; y < (number - x / 2); y++)
  35.                                   System.out.print(" ");
  36.      
  37.                                 for (int y = 0; y < x; y++)
  38.                                   System.out.print("*");
  39.      
  40.                                 System.out.println();
  41.                     }
  42.                     }
  43.                     else
  44.                     {
  45.                     for(int x = number-2; x > 0; x=x-2)
  46.                     {
  47.                             for (int y = 0; y < (number - x / 2); y++)
  48.                               System.out.print(" ");
  49.      
  50.                             for (int y = 0; y < x; y++)
  51.                               System.out.print("*");
  52.      
  53.                             System.out.println();
  54.                     }
  55.                    }
  56.                   }
  57.                     else if(d.length() == 0)
  58.                     {
  59.                         System.out.println("You entered nothing. Program will now terminate");                            
  60.                         break;
  61.  
  62.                     }
  63.                  }
  64.             }
  65.            
  66.             public static boolean Terve(String d)
  67.             {
  68.                  
  69.                      try  
  70.                      {  
  71.                          Integer.parseInt(d);  
  72.                          return true;  
  73.                       } catch(NumberFormatException nfe)  
  74.                       {  
  75.                           return false;  
  76.                       }  
  77.                
  78.                
  79.             }
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement