Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. public class Printing {
  2.    
  3.     public static void printStars(int amount) {
  4.         // 39.1
  5.         // you can print one star with the command
  6.         for(int i=0;i<amount;i++){
  7.             System.out.print("*");
  8.         }
  9.        
  10.         System.out.println();
  11.     }  
  12.    
  13.     public static void printSquare(int sideSize) {
  14.         // 39.2
  15.         System.out.println();
  16.         for(int i=0;i<sideSize;i++){
  17.             printStars(4);
  18.         }    
  19.        
  20.     }
  21.  
  22.     public static void printRectangle(int width, int height) {
  23.         // 39.3
  24.        
  25.         for(int i=0;i<height;i++){
  26.                 printStars(width);
  27.         }
  28.         System.out.println();
  29.     }
  30.  
  31.     public static void printTriangle(int size) {
  32.         // 39.4
  33.        
  34.         int increasing_size = (size - (size-1));
  35.        
  36.         for(int i=1;i<=size;i++){
  37.            
  38.             printStars(increasing_size);
  39.            
  40.             increasing_size += 1;  
  41.         }        
  42.        
  43.     }
  44.  
  45.     public static void main(String[] args) {
  46.         // Tests do not use main, yo can write code here freely!
  47.         // if you have problems with tests, please try out first
  48.         // here to see that the printout looks correct
  49.  
  50.         printStars(5);  
  51.         printStars(3);  
  52.         printStars(9);  
  53.        
  54.         System.out.println("\n---");  // printing --- to separate the figures
  55.         printSquare(4);
  56.         System.out.println("\n---");
  57.         printRectangle(17, 3);
  58.         System.out.println("\n---");
  59.         printTriangle(3);
  60.         System.out.println("\n---");
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement