Advertisement
Respec7

Diamond-Telerik

Apr 15th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4.  
  5. public class Hello {
  6.  
  7.         public static void main(String[]args) {
  8.  
  9.                 Scanner input = newScanner(System.in);
  10.  
  11.                
  12.  
  13.                 int size = input.nextInt();
  14.  
  15.                 if(size % 2 != 0){
  16.  
  17.                         int point1 = size /2;
  18.  
  19.                         int point2 = size /2;
  20.  
  21.                         int line = 0;
  22.  
  23.                         boolean reverse =false;
  24.  
  25.                         for(int n=0;n<=size*size-1; n++){
  26.  
  27.                                if(line>=size){
  28.  
  29.                                        System.out.println();
  30.  
  31.                                         line= 0;
  32.  
  33.                                        if(reverse == false){
  34.  
  35.                                                 point1--;
  36.  
  37.                                                 point2++;
  38.  
  39.                                        }else{
  40.  
  41.                                                 point1++;
  42.  
  43.                                                 point2--;
  44.  
  45.                                         }
  46.  
  47.                                 }
  48.  
  49.                                 if(line ==point1 || line == point2){
  50.  
  51.                                        System.out.print("+");
  52.  
  53.                                 }else{
  54.  
  55.                                        System.out.print("-");
  56.  
  57.                                 }              
  58.  
  59.                                 if(point1 ==0 || point2 == size){
  60.  
  61.                                         reverse = true;
  62.  
  63.                                 }
  64.  
  65.                                 line++;
  66.  
  67.                         }                      
  68.  
  69.                 }else{
  70.  
  71.                        System.out.println("Трябва да въведете нечетно число!");
  72.  
  73.                 }
  74.  
  75.         }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement