Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Printing {
- public static void printStars(int amount) {
- // 39.1
- // you can print one star with the command
- for(int i=0;i<amount;i++){
- System.out.print("*");
- }
- System.out.println();
- }
- public static void printSquare(int sideSize) {
- // 39.2
- System.out.println();
- for(int i=0;i<sideSize;i++){
- printStars(4);
- }
- }
- public static void printRectangle(int width, int height) {
- // 39.3
- for(int i=0;i<height;i++){
- printStars(width);
- }
- System.out.println();
- }
- public static void printTriangle(int size) {
- // 39.4
- int increasing_size = (size - (size-1));
- for(int i=1;i<=size;i++){
- printStars(increasing_size);
- increasing_size += 1;
- }
- }
- public static void main(String[] args) {
- // Tests do not use main, yo can write code here freely!
- // if you have problems with tests, please try out first
- // here to see that the printout looks correct
- printStars(5);
- printStars(3);
- printStars(9);
- System.out.println("\n---"); // printing --- to separate the figures
- printSquare(4);
- System.out.println("\n---");
- printRectangle(17, 3);
- System.out.println("\n---");
- printTriangle(3);
- System.out.println("\n---");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement