-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1_Question1.java
More file actions
49 lines (29 loc) · 882 Bytes
/
Lab1_Question1.java
File metadata and controls
49 lines (29 loc) · 882 Bytes
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
package day14_methodsPart2;
public class Lab1_Question1 {
public static void main(String[] args) {
// olcay // Jun 15, 2020
//Question-1
//Write a method that accepts a string and a non-negative number,
// and prints a larger string that is number copies of the original String
//stringTimes("Hi", 2); = > HiHi
//stringTimes("Hi", 3); = > HiHiHi
//stringTimes("Hi", 1); = > Hi
stringTimes("Hi", 1);
stringTimes1("Hi", 5);
}
private static void stringTimes(String string, int i) {
int number=0;
while(number<i) {
System.out.print(string);
number++;
}
System.out.println();
}
private static void stringTimes1(String string, int number) {
String str = "";
for(int i=0; i<number; i++) {
str = str+string;
}
System.out.println(str);
}
}