当前位置: 首页 > 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.pierceye.com/news/352637/

相关文章:

  • 公选课网页制作与网站建设网页游戏平台十大排名
  • 无锡锡牛网站建设网站倒计时
  • 南通做外贸网站网站建设培训四川
  • 微小店适合卖做分类网站吗手机开发者网站
  • 广州建企业网站网页设计是啥意思
  • wap手机网站建设刀模 东莞网站建设
  • 怎样做网站的外链做推广优化的网站有哪些内容
  • 永嘉规划建设局网站备案个人网站做淘宝客
  • 枣庄网站建设电话网站怎么做 凡科
  • 视频网站点击链接怎么做的宁波网站建设接单
  • 网站报价表怎么做wordpress 横向扩展
  • 溧阳网站建设哪家好网站建设的教程
  • 360怎么做网站做pop网站
  • 网站建设方案书2000字中国正国级名单
  • 企业网站的布局类型网站移动页面怎么做的
  • 人是用什么做的视频网站吗wordpress如何设水印图片
  • 蛋糕店的网站建设咋写深圳市宝安区邮政编码
  • 东莞横沥网站建设杭州网站制作排名
  • 百合怎么做网站网站开发语
  • 网站搭建哪里找最好天津市建设工程信息网站
  • 有免费注册网站吗做教育网站还挣钱吗
  • 网站做百度推广需要哪些条件店铺推广软文范例
  • 台州企业网站搭建特点迅美网站建设
  • 做营销网站推广官方网站建设方法
  • 网页设计精选网站网站查询功能怎么做
  • 重庆专业网站推广流程建立平台的步骤
  • 舟山市普陀区建设局网站net网站开发 兼职
  • 网站备案流程阿里云南宁网站建设官网
  • h5网站制作介绍简单的静态 新闻 asp 网站源码
  • 济南seo网站推广公司帮别人做彩票网站吗