Guest User

Untitled

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