-2

我是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);
        }

  }
}`
4

1 回答 1

0
System.out.println("Please, Enter:");
    BufferedReader consoleIn =
        new BufferedReader(new InputStreamReader(System.in));
    String stringInt = consoleIn.readLine();
    int fromConsoleInput = Integer.parseInt(stringInt);
于 2015-02-24T08:07:37.483 回答