File tree Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .base ;
2
+
3
+
4
+ import java .util .Scanner ;
5
+
6
+ public class ScannerDemo {
7
+ public static void main (String [] args ) {
8
+ //输入输出,牛客网之类的平台会用到
9
+ Scanner scanner = new Scanner (System .in );
10
+ while (scanner .hasNext ()) {
11
+ System .out .println (scanner .next ());
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ package com .string ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class SpecialString {
6
+
7
+ public static void main (String [] args ) {
8
+ Scanner scanner = new Scanner (System .in );
9
+ while (scanner .hasNext ()) {
10
+ System .out .println (isTarget (scanner .next ()));
11
+ }
12
+ }
13
+
14
+ /**
15
+ * 判断是否回文字符串
16
+ *
17
+ */
18
+ public static boolean isTarget (String str ) {
19
+ if (str ==null ) {
20
+ return false ;
21
+ }
22
+ boolean isTar = true ;
23
+ //双指针
24
+ int length = str .length ();
25
+ for (int i = 0 ; i < length ; i ++) {
26
+ if (str .charAt (i ) != str .charAt (length -1 -i )) {
27
+ return false ;
28
+ }
29
+ }
30
+ return isTar ;
31
+ }
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ package com .string ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ public class SolutionTest {
7
+
8
+ /**
9
+ * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
10
+ *
11
+ * 一个数如果恰好等于它的因子之和。6=1+2+3.
12
+ *
13
+ * @param wanCount int整型 10000以内
14
+ * @return int整型ArrayList
15
+ */
16
+ public ArrayList <Integer > fun (int wanCount ) {
17
+ // write code here
18
+ ArrayList <Integer > list = new ArrayList <>();
19
+ if (wanCount ==0 || wanCount ==1 ) {
20
+ list .add (wanCount );
21
+ return list ;
22
+ }
23
+ for (int i = 1 ; i <= wanCount ; i ++) {
24
+ //从1开始一直遍历到 i
25
+ int sum = i ;
26
+ for (int j = 1 ; j < i ; j ++) {
27
+ if (i %j ==0 ) {
28
+ sum -=j ;
29
+ }
30
+ }
31
+ if (sum ==0 ) {
32
+ list .add (i );
33
+ }
34
+ }
35
+ return list ;
36
+
37
+ }
38
+
39
+ }
You can’t perform that action at this time.
0 commit comments