查看: 1501|回复: 0

[Java学习] 借书系统初级学习各位大神多指教

发表于 2018-2-2 08:00:02

package jieshuxitong;

import java.util.Scanner;

public class jiashu {

  1. public static void main(String[] args) {
  2. // TODO Auto-generated method stub
  3. System.out.println("**********欢迎使用借书系统*************");
  4. Scanner input = new Scanner(System.in);
  5. while (true) {
  6. System.out.println("输入命令:1-按照名称查找图书;2-按照序号查找图书");
  7. try {
  8. switch (input.next()) {
  9. case "1":
  10. System.out.println("请输入图书名称:");
  11. try {
  12. String c = input.next();
  13. switch (c) {
  14. case "chinese":
  15. System.out.println("book:chinese");
  16. break ;
  17. case "mathematical":
  18. System.out.println("book:mathematical");
  19. break;
  20. case "english":
  21. System.out.println("book:english");
  22. break;
  23. default:
  24. System.out.println("没有" + c + "图书");
  25. continue;
  26. }
  27. } catch (Exception e) {
  28. // TODO: handle exception
  29. Exception as = new Exception("请输入字符串!");
  30. as.initCause(e);
  31. throw as;
  32. }
  33. break;
  34. case "2":
  35. System.out.println("请输入图书序号:");
  36. try {
  37. String g = input.next();
  38. switch (g) {
  39. case "1":
  40. System.out.println("book:chinese");
  41. break;
  42. case "2":
  43. System.out.println("book:mathematical");
  44. break;
  45. case "3":
  46. System.out.println("book:english");
  47. break;
  48. default:
  49. System.out.println("没有" + g + "图书");
  50. continue;
  51. }
  52. } catch (Exception e) {
  53. // TODO: handle exception
  54. Exception as = new Exception("请输入整数!");
  55. as.initCause(e);
  56. throw as;
  57. }
  58. break;
  59. default :
  60. System.out.println("输入不正确!");
  61. break;
  62. }
  63. } catch (Exception e) {
  64. // TODO: handle exception
  65. System.out.println("输错了哈哈哈");
  66. }
  67. }
  68. }
复制代码

}



回复

使用道具 举报