@PhilAnderson/

StringsAndLoops

Java

No description

fork
loading
Files
  • Main.java
  • Main.class
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Main {
  public static void main(String[] args) {
    System.out.println(stars(7));
    System.out.println(spacedStars(10,5));
    System.out.println(spacedDollars(20, 3, 1));
    System.out.println(stripes(9,3));
    System.out.println(square(3));
    System.out.println("Mod: " + 2 % 3);
    // System.out.println(checkerboard(3));
  }
  public static String stars(int num){
    String str = "";
    for(int i = 0; i < num; i++){
      str += "*";
    }
    return str;
  }
  public static String spacedStars(int numCharacters, int starInterval){
    String str = "";
    for(int i = 0; i < numCharacters; i++){
      if(i % starInterval == 0){
        str += "*";
      } else {
        str += "-";
      }
    }
    return str; 
  }
  public static String spacedDollars(int numCharacters, int dollarInterval, int dollarStartPoint){
    String str = "";
    for(int i = 0; i < numCharacters; i++){
      if(i % dollarInterval == dollarStartPoint % dollarInterval){
        str += "$";
      } else {
        str += "-";
      }
    }
    return str; 
  }

  public static String square(int num){
    String str = "";
    for(int i = 0; i < num; i++){
      for(int j = 0; j < num; j++){
        str += "#";
      }
      str += "\n";
    }
  return str;
  }  
  
  public static String stripes(int width, int spacing){
    String str = "";
    for(int i = 1; i <= width; i++){
      if(i % spacing == 0)
        str += "*";
      else
        str += "|";
    }
    return str;
  }

  

  public static String checkerboard(int num){
    String str = "";
    for(int i = 0; i < num; i++){
      for(int j = 0; j < num; j++){
        str += "o";
      }
      str += "\n";
    }
  return str;
  }
}