【问题标题】:java System.in How can I use System.in.read()java System.in 如何使用 System.in.read()
【发布时间】:2015-04-25 18:44:43
【问题描述】:

我是java新手。

我应该使用 System.in.read() 来解决我的程序

但我不知道,它到底是做什么的?

感谢帮助

我的问题:

取多个用户。如果数字小于 1, 打印错误。 否则,打印 2 ^ ( 1 个传入号码 ) 的结果。 "一次用 for AND 一次用 while"

'int i ; 
int  num ;
System.out.println("enter a number : ");
for (i=1 ; (num = System.in.read()) != '\r' ; i++  ) 
{

  if( num <1 )
  {
  System.out.println("illegal value! \n enter a number"); 
  }

      else
      {
        int j; int pow = 1;
        for (j = 1 ; j <= num ; j++) 
        {
          pow *=2 ;
          System.out.println(pow);
        }

  }
}`

【问题讨论】:

    标签: java for-loop system.in


    【解决方案1】:
    System.out.println("Please, Enter:");
        BufferedReader consoleIn =
            new BufferedReader(new InputStreamReader(System.in));
        String stringInt = consoleIn.readLine();
        int fromConsoleInput = Integer.parseInt(stringInt);
    

    【讨论】:

    • 问题:取多个用户。如果数字小于 1,* 打印错误。否则,打印 2 ^ ( 1 个传入号码 ) 的结果。 * 一次使用 for AND 一次使用 while
    • 我的代码:int i;整数 ; System.out.println("输入一个数字:"); for (i=1 ; (num = System.in.read()) != '\r' ; i++ ) { if( num
    猜你喜欢
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多