当前位置: 首页 > news >正文

做网站 广告收入企业网站源码 可去版权

做网站 广告收入,企业网站源码 可去版权,公司网站宣传设计,建设360导航网站的目的是什么意思最近在做java作业, 发现了一个问题, 就是nextline其实会接收缓冲区的\r, 使得在程序运行时nextline像是跳过了一样, 其实不然, 它只是读取了上一个enter时的\r, 如我的如下功能代码 public void run() {Scanner scan new Scanner(System.in);int ord, book_order;int flag 0;…最近在做java作业, 发现了一个问题, 就是nextline其实会接收缓冲区的\r, 使得在程序运行时nextline像是跳过了一样, 其实不然, 它只是读取了上一个enter时的\r, 如我的如下功能代码 public void run() {Scanner scan new Scanner(System.in);int ord, book_order;int flag 0;String isbn new String();String nme new String();while (flag 0) {System.out.println(Function List:);System.out.println(1.Show the book list);System.out.println(2.Find book);System.out.println(3.Add book);System.out.println(4.Delete book);System.out.println(0.Exit);System.out.println(Please input the functon order:);ord scan.nextInt();switch (ord) {case 0: {flag 1;break;}case 1: {Print();break;}case 2: {Scanner in new Scanner(System.in);System.out.println(Please input the ISBN of book you want to find:);isbn in.nextLine();book_order Find(isbn);if (book_order ! 0) {System.out.println(Success!);System.out.println(Name: books[book_order].name);System.out.println(ISBN: books[book_order].ISBN);System.out.println();} else {System.out.println(Error!No such book!);System.out.println();}break;}case 3: {Scanner in new Scanner(System.in);System.out.println(Please input the name of the book:);nme scan.nextLine();System.out.println(Please input the ISBN of the book:);isbn scan.nextLine();if (Add(nme, isbn)) {System.out.println(Add successfully!);System.out.println();} else {System.out.println(Failed to add!Its out of range!);System.out.println();}break;}case 4: {System.out.println(Please input the ISBN of book you want to delete:);isbn scan.nextLine();if (Del(isbn)) {System.out.println(Delete successfully!);System.out.println();} else {System.out.println(Failed to delete!No such book!);System.out.println();}break;}}}scan.close();} }在这里, 我一开始就已经实例化了一个scanner对象, 命名为scan, 然后在输入功能选项时我们调用了nextInt, 那么在输入完之后, 整数被读取进去了, 但是那个\r还留在scan的buffer区域, 所以, 如果我们添加书籍的话, 再次使用scan的nextline来读取书名的话, nextline就会得到scan的buffer区域中的\r,导致程序错误, 所以,在这里看到老师的代码之后, 得到启发, 重新新建一个scanner对象, 在这里可以使用Scanner in, 这样的话, in的buffer区域中就没有之前存留的\n, 那么这个时候我们再输入一行, 则不会出现\r被读取的问题. public void run() {Scanner scan new Scanner(System.in);int ord, book_order;int flag 0;String isbn new String();String nme new String();while (flag 0) {System.out.println(Function List:);System.out.println(1.Show the book list);System.out.println(2.Find book);System.out.println(3.Add book);System.out.println(4.Delete book);System.out.println(0.Exit);System.out.println(Please input the functon order:);ord scan.nextInt();switch (ord) {case 0: {flag 1;break;}case 1: {Print();break;}case 2: {Scanner in new Scanner(System.in);System.out.println(Please input the ISBN of book you want to find:);isbn in.nextLine();book_order Find(isbn);if (book_order ! 0) {System.out.println(Success!);System.out.println(Name: books[book_order].name);System.out.println(ISBN: books[book_order].ISBN);System.out.println();} else {System.out.println(Error!No such book!);System.out.println();}break;}case 3: {Scanner in new Scanner(System.in);System.out.println(Please input the name of the book:);nme in.nextLine();System.out.println(Please input the ISBN of the book:);isbn in.nextLine();if (Add(nme, isbn)) {System.out.println(Add successfully!);System.out.println();} else {System.out.println(Failed to add!Its out of range!);System.out.println();}break;}case 4: {System.out.println(Please input the ISBN of book you want to delete:);isbn scan.nextLine();if (Del(isbn)) {System.out.println(Delete successfully!);System.out.println();} else {System.out.println(Failed to delete!No such book!);System.out.println();}break;}}}scan.close();} }运行结果如下: 此外, 也可以和cpp一样, 使用一次scan.nextLine将那个\r读取.
http://www.zqtcl.cn/news/352637/

相关文章:

  • iis网站防盗链济宁官方网站
  • 网址查询地址查询站长之家在海南注册公司需要什么条件
  • 网站开发兼职平台网站建设需要多少钱小江网页设计
  • 最专业的网站建设收费2021没封的网站有人分享吗
  • 站酷设计网站官网入口文字设计wordpress是服务器吗
  • 律师手机网站模板天津做推广的公司
  • 西安市高新区建设规划局网站织梦小说网站模板下载地址
  • 网站开发简历 自我评价网页设计报告论文
  • 如何让网站不被收录不备案 国内网站
  • 站长之家域名买天猫店铺去哪里买
  • asp.net做的网站模板下载万网x3 wordpress
  • 设计网站设计目标天津市建设工程管理总队网站
  • 网站开始怎么做上海响应式网页建设
  • 网站备案 seo免费二维码制作网站
  • 删除网站备案网站建设湖南岚鸿建设
  • 做vlogger的网站有哪些长沙网站排名技巧
  • 媒体营销平台商品seo关键词优化
  • 芜湖先锋网站两学一做wordpress菜单顶部
  • 网站策划怎么样一级域名网站如何申请
  • 烟台高端网站开发网站开发哪个公司好
  • 广州网站定制开发方案南宁网站 制作
  • php做网站需要后台吗郑州建网站十大
  • 网站跳出率是什么意思百度服务
  • 建站 discuz开发者导航
  • 有哪些网站可以做毕业设计外贸网站发外链
  • 如何使用网站模板计算机培训班有用吗
  • 本地宁波网站建设电子商务网站建设工具都有那些
  • 网站建设的基本目标免费 wordpress企业主题
  • 专业网站建设微信商城开发规划馆网站建设
  • 网站建设公司沈阳西安建设工程信息交易中心官网