import java.io.IOException;
import java.io.InputStream;
public class IsTriangle {public static void main(String[] args){
   InputStream i=System.in;
   try {
   
    System.out.println(i.read());
   } catch (IOException e) {
   
    e.printStackTrace();
   }}

输入30 输出51

解决方案 »

  1.   

    从输入流中读取数据的下一个字节。返回 0 到 255 范围内的 int 字节值。如果因为已经到达流末尾而没有可用的字节,则返回值 -1。在输入数据可用、检测到流末尾或者抛出异常前,此方法一直阻塞。 你输入a试试。
      

  2.   

    i.read()只读入了3,然后输出3的ascii值
      

  3.   

    package com.xuz.csdn.july05;import java.io.IOException;
    import java.io.InputStream;public class InputStreamTest { public static void main(String[] args) {
    InputStream is = System.in;
    byte[] b = new byte[1024];
    try {
    int size = is.read(b);
    System.out.println(new String(b,0,size));
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }}
      

  4.   

    知道i.read()读取的是字节就知道了么!
      

  5.   

    /*import java.io.IOException;
    import java.util.Scanner;
    public class IsTriangle {

    public void CheckInt(int i){
    if(i<=1||i>=100){
    System.out.println(i+"的取值不在允许取值的范围内");
    return;
    }



    }
    public void CheckTriangle(int a,int b,int c){
    if(a<b+c&&b<a+c&&c<a+c){
    if(a==b&&b==c){
    System.out.println("等边三角形");
    return;
    }
    if(a==b||b==c||a==c){
    System.out.println("等腰三角形");
    return;

    }
    System.out.println("不等边三角形");



    }
    }

    public static void main(String[] args){
    //Scanner s=new Scanner(System.in);
    //int a=s.nextInt();
    //int b=s.nextInt();
    /int c=s.nextInt();


    IsTriangle iT=new IsTriangle();
    iT.CheckInt(a);
    iT.CheckInt(b);
    iT.CheckInt(c);

    iT.CheckTriangle(a,b,c);
    System.out.println(System.in);





    }
    }
    *//*
    import java.io.IOException;
    import java.io.InputStream;
    public class IsTriangle {public static void main(String[] args){
       InputStream i=System.in;
       try {
       
        System.out.println(i.read());
       } catch (IOException e) {
       
        e.printStackTrace();
       }}
    }*/
    /*import java.io.IOException;
    import java.io.InputStream;public class IsTriangle {    public static void main(String[] args) {
            InputStream is = System.in;
            byte[] b = new byte[1024];
            try {
                int size = is.read(b);
                System.out.println(new String(b,0,size));
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }}*/
    import java.io.IOException;
    import java.io.InputStream;public class InputStreamTest {    public static void main(String[] args) {
            InputStream is = System.in;
            byte[] b = new byte[1024];
            try {
                int size = is.read(b);//读入缓冲区的总字节数,如果由于流末尾已到达而不再有数据,则返回 -1
                System.out.println(new String(b,0,size));
    /*            public String(byte[] bytes,
                        int offset,
                        int length)构造一个新的 String,方法是使用指定的字符集解码字节的指定子数组。新的 String 的长度是一个字符集函数,因此不能等于该子数组的长度。 
          当给定字节在给定字符集中无效的情况下,该构造方法无指定的行为。当需要进一步控制解码过程时,应使用 CharsetDecoder 类。 
          参数:
          bytes - 要解码为字符的字节
          offset - 要解码的首字节的索引
          length - 要解码的字节数 
          抛出: 
          IndexOutOfBoundsException - 如果 offset 和 length 参数索引字符超出 bytes 数组的范围*/
                System.out.println(b[0]);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }}
      

  6.   

    import java.io.IOException;
    import java.io.InputStream;public class InputStreamTest {    public static void main(String[] args) {
            InputStream is = System.in;
            byte[] b = new byte[1024];
            try {
                int size = is.read(b);//读入缓冲区的总字节数,如果由于流末尾已到达而不再有数据,则返回 -1
                System.out.println(new String(b,0,size));
    /*            public String(byte[] bytes,
                        int offset,
                        int length)构造一个新的 String,方法是使用指定的字符集解码字节的指定子数组。新的 String 的长度是一个字符集函数,因此不能等于该子数组的长度。 
          当给定字节在给定字符集中无效的情况下,该构造方法无指定的行为。当需要进一步控制解码过程时,应使用 CharsetDecoder 类。 
          参数:
          bytes - 要解码为字符的字节
          offset - 要解码的首字节的索引
          length - 要解码的字节数 
          抛出: 
          IndexOutOfBoundsException - 如果 offset 和 length 参数索引字符超出 bytes 数组的范围*/
                System.out.println(b[0]);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }}