day07-常用类-匿名对象
This commit is contained in:
23
day07/src/com/inmind/scanner01/Demo04.java
Normal file
23
day07/src/com/inmind/scanner01/Demo04.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.inmind.scanner01;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/*
|
||||||
|
匿名对象:没有名字的对象
|
||||||
|
匿名对象的使用场景:当一个对象只要被使用一次的时候,可以使用匿名对象来简单实现
|
||||||
|
|
||||||
|
new Scanner(System.in):就是匿名对象
|
||||||
|
Scanner sc = new Scanner(System.in);就是有了对象名,可以重复操作
|
||||||
|
*/
|
||||||
|
public class Demo04 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//获取一个整数即可
|
||||||
|
/*Scanner sc = new Scanner(System.in);
|
||||||
|
int i = sc.nextInt();*/
|
||||||
|
|
||||||
|
/*int i = new Scanner(System.in).nextInt();
|
||||||
|
System.out.println(i);*/
|
||||||
|
|
||||||
|
System.out.println(new Scanner(System.in).nextInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user