Skip to content

Commit 37ea587

Browse files
committed
Java第十二天
1 parent ecaf465 commit 37ea587

63 files changed

Lines changed: 1069 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
2.24 MB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

day12/code/day12_Scanner/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>day12_Scanner</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7
575 Bytes
Binary file not shown.
904 Bytes
Binary file not shown.
783 Bytes
Binary file not shown.
882 Bytes
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cn.itcast_01;
2+
3+
import java.io.InputStream;
4+
import java.util.Scanner;
5+
6+
/*
7+
* Scanner:JDK5以后,用于帮助我们实现键盘录入数据的。
8+
*
9+
* 构造方法:
10+
* public Scanner(InputStream source)
11+
*/
12+
public class ScannerDemo {
13+
public static void main(String[] args) {
14+
// 创建键盘录入对象
15+
// Scanner sc = new Scanner(System.in);
16+
17+
// public Scanner(InputStream source)
18+
19+
// System类下有这样的一个成员变量
20+
// public static final InputStream in;
21+
// InputStream is = System.in;
22+
23+
// 假如Demo类下有一个变量
24+
// public static final int x;
25+
// public static final Student s;
26+
// int y = Demo.x;
27+
// Student student = Demo.s;
28+
29+
// InputStream is = System.in; //子类对象
30+
// Scanner sc = new Scanner(is);
31+
32+
Scanner sc = new Scanner(System.in);
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package cn.itcast_02;
2+
3+
import java.util.Scanner;
4+
5+
/*
6+
* 成员方法:
7+
* hasNextXxx():判断下一个输入项是不是指定的数据类型
8+
* nextXxx():获取该类型的数据
9+
*
10+
* 注意:
11+
* 键盘录入数据,需要的是int类型,我却给了一个字符串。
12+
* 在控制台就提示:InputMismatchException 输入不匹配异常。
13+
*
14+
*/
15+
public class ScannerDemo {
16+
public static void main(String[] args) {
17+
Scanner sc = new Scanner(System.in);
18+
19+
System.out.println("请输入一个整数:");
20+
21+
if (sc.hasNextInt()) {
22+
int number = sc.nextInt();
23+
System.out.println(number);
24+
}
25+
26+
System.out.println("over");
27+
}
28+
}

0 commit comments

Comments
 (0)