Guest User

Untitled

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