Chinaunix首页 | 论坛 | 博客
  • 博客访问: 433045
  • 博文数量: 79
  • 博客积分: 8385
  • 博客等级: 中将
  • 技术积分: 3625
  • 用 户 组: 普通用户
  • 注册时间: 2005-09-26 14:42
文章分类

全部博文(79)

文章存档

2011年(10)

2010年(40)

2009年(21)

2008年(8)

分类: 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.}
阅读(630) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~