Topic: System.in.read()输入int后print怎么变了?

  Print this page

1.System.in.read()输入int后print怎么变了? Copy to clipboard
Posted by: netfsy
Posted on: 2004-12-09 10:24

class readtext
{
  public static void main(String args[])
  {
    int ch;
    ch=1;
    System.out.println("Enter a number:");
    try
    {
      ch=System.in.read();
      }
    catch(Exception e)
    {
      System.out.println("Cannot read:"+ch);
      }
    System.out.println("The nember is:"+ch);输出的总是其他的数字
    System.out.println("The character is:"+(char)ch);输出的是我输入的数字,该是字符吧
    }
  }

2.Re:System.in.read()输入int后print怎么变了? [Re: netfsy] Copy to clipboard
Posted by: netfsy
Posted on: 2004-12-09 10:56

补充一下:和系统没关系吧,偶是xp的系统
各位大虾帮帮忙啦,先谢了~

3.Re:System.in.read()输入int后print怎么变了? [Re: netfsy] Copy to clipboard
Posted by: vainglory
Posted on: 2004-12-09 16:41

System.in.read();149a97

4.Re:System.in.read()输入int后print怎么变了? [Re: netfsy] Copy to clipboard
Posted by: netfsy
Posted on: 2004-12-10 15:03

是的是的,就是这个样子.
但int i=System.in.read();怎么会是字符呢?read()里写入int也是错的,该在哪里限制一下呢?

5.Re:System.in.read()输入int后print怎么变了? [Re: netfsy] Copy to clipboard
Posted by: ch_tj2k
Posted on: 2004-12-10 17:30

System.in.read()只能读一个输入的字符,函数返回值类型是byte。

6.Re:System.in.read()输入int后print怎么变了? [Re: netfsy] Copy to clipboard
Posted by: plam
Posted on: 2004-12-11 18:53

int i = Integer.parseInt(in.readLine());


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923