Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public class Schachbrett {
  2.  
  3.   public static void main(String[] args) {
  4.  
  5.     // SANITY CHECKS
  6.    
  7.     if (args.length != 1) {
  8.       System.out.println("Usage: java Schachbrett {number}");
  9.       return;
  10.     }
  11.    
  12.     int size;
  13.      
  14.     try {
  15.       size = Integer.parseInt(args[0]);
  16.     } catch (NumberFormatException nfe) {
  17.       System.out.println("Please enter a valid number");
  18.       return;
  19.     }
  20.    
  21.     if (size <= 0) {
  22.       System.out.println("Please enter a number above 0");
  23.       return;
  24.     }
  25.    
  26.    
  27.     // DRAWING
  28.     boolean isBlack = true;
  29.     for(int x = 0; x < size; x++) {
  30.       for(int y = 0; y < size; y++) {
  31.         System.out.print(isBlack ? "*" : " ");
  32.         isBlack = !isBlack;
  33.       }
  34.       System.out.print("\n");
  35.     }
  36.   }
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement