分类: Java
2011-03-16 18:29:57
package
org.kodejava.example.util;
02.
03.
import
java.util.Scanner;
04.
05.
public
class
ScannerDemo {
06.
public
static
void
main(String[] args) {
07.
Scanner scanner =
new
Scanner(System.in);
08.
09.
//
10.
// Read string input for username
11.
//
12.
System.out.print(
"Username: "
);
13.
String username = scanner.nextLine();
14.
15.
//
16.
// Read string input for password
17.
//
18.
System.out.print(
"Password: "
);
19.
String password = scanner.nextLine();
20.
21.
//
22.
// Read an integer input for another challenge
23.
//
24.
System.out.print(
"What is 2 + 2: "
);
25.
int
result = scanner.nextInt();
26.
27.
if
(username.equals(
"admin"
) && password.equals(
"secret"
) && result ==
4
) {
28.
System.out.println(
"Welcome to Java Application"
);
29.
}
else
{
30.
System.out.println(
"Invalid username or password, access denied!"
);
31.
}
32.
}
33.
}