-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q1.java
36 lines (33 loc) · 1.06 KB
/
Q1.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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
public class Q1 {
public static void main(String[] args) throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String[] inp = read.readLine().split("");
String str="";
//ArrayList strarray = new ArrayList();
int ans = 0;
for (int i = 0; i < inp.length; i++) {
for (int j = i; j < inp.length; j++) {
str=str+String.valueOf(inp[j]);
System.out.println(str);
int temp = Integer.parseInt(str);
if (prime(temp)==1 && temp > ans) {
ans = temp;
}
}
str="";
}
System.out.println("最大的質數值為"+(ans));
}
public static int prime(int number){
for (int i = 2; i < number; i++) {
if (number % i == 0 && i != number) {
return 0;
}
}
return 1;
}
}