ITPub博客

首页 > 应用开发 > > int n=sc.nextInt();在while循环后面与前面的不同

int n=sc.nextInt();在while循环后面与前面的不同

作者:netroop 时间:2019-07-29 13:51:11 0 删除 编辑
Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

while(true){

System.out.println(n);

}这代码输入1  输出为 一个1  (且程序不断运行)



Scanner sc=new Scanner(System.in);

int n;

while(true){

n=sc.nextInt();

System.out.println(n);

}

这代码输入1 后 不断输出1,(且程序不断运行)

为什么会这样,都应该不断输出1的吗。谢谢

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4741/viewspace-3150305/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-25

  • 博文量
    152
  • 访问量
    1068