-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest2.java
More file actions
38 lines (37 loc) · 898 Bytes
/
Test2.java
File metadata and controls
38 lines (37 loc) · 898 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
package Demo1;
public class Test2 {
public static void main(String[] args) {
new Test2().printNumber();
}
private void printNumber() {
int[] arr = new int[100];
String[] strArr = new String[100];
//´´½¨100µÄÊý×é
for(int i=0;i<arr.length;i++) {
arr[i]=i+1;
}
for (int i : arr) {
if(i%3==0&&i%5!=0) {
strArr[i-1] = "Fizz";
}else if(i%3!=0&&i%5==0) {
strArr[i-1] = "Buzz";
}else if(i%3==0&&i%5==0) {
strArr[i-1] = "FizzBuzz";
}else{
String istr = String.valueOf(i);
if(istr.contains("3")&&!istr.contains("5")) {
strArr[i-1] = "Fizz";
}else if(istr.contains("5")&&!istr.contains("3")) {
strArr[i-1] = "Buzz";
}else if(istr.contains("3")&&istr.contains("5")) {
strArr[i-1] = "FizzBuzz";
}else {
strArr[i-1] = String.valueOf(i);
}
}
}
for (String str : strArr) {
System.out.println(str);
}
}
}