class aaa
{
        public static void main (String args[])
        {
         int x=0;
         try
      {
          x=System.in.read();
      }
        catch
          (Exception e){}
            System.out.println(x*6);   
        }               
}   
                  如上,输入一个字符,然后*6。
                  我输入2,结果显示是300,把2对应的ASC码50去乘了6。
                  请问大家,有什么办法输入2就用2去*6呢???           小弟是JAVA初学者,,,还没怎么入门,大哥们是怎么成长的呢? 我花时间搞清这些小问题有意义吗????   谢谢大家了!!

解决方案 »

  1.   

    import java.io.*;
    class aaa
    {
            public static void main (String args[])
            {
             String str = null;
             int x;
             try
          {
              BufferedReader in = new BufferedReader(new InputStream(System.in));
                         str = in.readLine();
                         x = Integer.parseInt(str);
          }
            catch
              (Exception e){}
                System.out.println(x*6);   
            }               
    }   就可以了
      

  2.   

    谢谢magiczha大哥~~~
                 不过,,第10行编译错误?  是不是哪里打错啦??
                       PS:这个内容有点深奥,,,看来要到以后才能理解.
      

  3.   

    //第10行的错误修正为BufferedReader in =
      new BufferedReader(
        new InputStreamReader(
          System.in));//错误出在new InputStream,改为new InputStreamReader@.@||~
      

  4.   

    将system.in输入的字符转换为数值就行了,即: Integer.parseInt(x);附:
    class aaa
    {
            public static void main (String args[])
            {
             int x=0;
             try{
    x=System.in.read();
    }catch(Exception e){}
    System.out.println(Integer.parseInt(x)*6));   
            }               
    }
      

  5.   

    midthinker,,,  改过后还是通不过    16行有错说X未初始化。。??edward0716大哥的方法似乎是最简便的解决方法~~~~  不过编译通不过,,,修改了最后一行的一个明显的括号错误外,还是有错~~~   求解,求解~~!
      

  6.   

    import java.io.*;
    class aaa
    {
            public static void main (String args[])
            {
             String str = null;
             int x=1;
             try
          {
              BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                         str = in.readLine();
                         x = Integer.parseInt(str);
          }
            catch
              (Exception e){}
                System.out.println(x*6);   
            }               
    }  
    大哥这样就对了哈,要注意细心点撒!!呵呵
      

  7.   

    class aaa
    {
            public static void main (String args[])
            {
             int x=0;
             try{
    x=System.in.read();
    }catch(Exception e)
            {
    System.out.println((Integer.parseInt(x))*6)); 
            }  
            }               
    }
      

  8.   

    import java.io.*; class MulYourInput {
      public static void main( String[] args ) throws IOException {
        BufferedReader in =
          new BufferedReader(
            new InputStreamReader(
     System.in));

        try {
          System.out.print( "Please input a number: " );
          int x = Integer.parseInt( in.readLine() );
          System.out.println( "The result is (x * 6): " + (x * 6) );
        } catch( IOException e ) {}
      }
    } /// @.@||~以上代码经测试通过,均真实可用,上海市公证局公证(哈哈)
    另:Java IO 系统是个结构相当复杂的结构设计,如果要深入JAVA,就必须好好掌握整个IO体系
      

  9.   

    谢谢 luoxueyong兄~~~~~  终于通过了哈~~!!    不过这个方法小弟现在还不好理解,  第2个方法很好!! 可是wangc4(wang)兄最后修改后还是有错通不过~~~~~   问题出在哪里呀??
      

  10.   

    wangc4的问题出在System.in是一个Stream对象,它所捕获并返回的类型将是Byte
    Integer.parseInt( String s ),可以看出,接收一个String对象,而不是Byte对象。在JAVA IO设计体系中分为Stream && Char流这两个派别,使用前一种方法,正是将一个Stream流转换成char流,从而获得一个String对象,对IO设计的具体分析应该不算基础了吧可能比较进阶了,可以参考《Think in java》,其中对IO库的描述应该算相当通透的。
    @.@||~
      

  11.   

    谢谢midthinker大哥不厌其烦的赐教~~~!!       小弟现在才刚看到类呢,,那点东西就把俺搞的晕头转向了。。
          看来这是比较深的内容了!  多谢大哥指路~~