Skip to content

Commit 9519586

Browse files
committed
anonymous4__匿名对象
1 parent 8ceb737 commit 9519586

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

javaAPI/Scanner/anonymous4.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* @由于个人水平有限, 难免有些错误, 还请指点:
3+
* @Author: cpu_code
4+
* @Date: 2020-09-13 14:29:24
5+
* @LastEditTime: 2020-09-13 14:36:32
6+
* @FilePath: \java\javaAPI\Scanner\anonymous4.java
7+
* @Gitee: [https://gitee.com/cpu_code](https://gitee.com/cpu_code)
8+
* @Github: [https://github.com/CPU-Code](https://github.com/CPU-Code)
9+
* @CSDN: [https://blog.csdn.net/qq_44226094](https://blog.csdn.net/qq_44226094)
10+
* @Gitbook: [https://923992029.gitbook.io/cpucode/](https://923992029.gitbook.io/cpucode/)
11+
*/
12+
package javaAPI.Scanner;
13+
14+
import java.util.Scanner;
15+
16+
public class anonymous4 {
17+
public static void main(String[] args){
18+
19+
// 普通使用方式
20+
//Scanner sc = new Scanner(System.in);
21+
//int num = sc.nextInt();
22+
23+
// 匿名对象的方式
24+
//int num = new Scanner(System.in).nextInt();
25+
//System.out.println("输入的是:" + num);
26+
27+
// 使用一般写法传入参数
28+
//Scanner sc = new Scanner(System.in);
29+
//methodParam(sc);
30+
31+
// 使用匿名对象来进行传参
32+
methodParam(new Scanner(System.in));
33+
34+
Scanner sc = methodReturn();
35+
int num = sc.nextInt();
36+
System.out.println("输入 :" + num);
37+
}
38+
39+
public static void methodParam(Scanner sc) {
40+
int num = sc.nextInt();
41+
System.out.println("输入是" + num);
42+
}
43+
44+
public static Scanner methodReturn() {
45+
//Scanner sc = new Scanner(System.in);
46+
//return sc;
47+
return new Scanner(System.in);
48+
}
49+
}
50+
51+
/*
52+
2
53+
输入是2
54+
2
55+
输入 :2
56+
*/

0 commit comments

Comments
 (0)