c=(int)System.in.read();
大哥,我也是新手,但是这样可以吗?好像不能像c那样呀.

解决方案 »

  1.   

    但是怎么付值呀?我是要求输入一个c的值啊!能教教我吗就是在我的程序上做一下修改使它可以被javac.谢谢
      

  2.   


    import java.io.*;
    public class snow{
    public static void main(String args[]){
        int c,b;
        BufferedReader br = new
                BufferedReader(new InputStreamReader(System.in));
        System.out.print("Please enter v of c:");
        try{
            
        c = (char) br.read();
    }catch(IOException e){};
            b=c+18;
        System.out.print("b="+b);
    }
    }
      

  3.   

    c = (char) br.read();
    改成c = (int) br.read();
    笔误
      

  4.   

    一样的,除非,你再定义c 之后和用到c之前对他显性初始化。
    如:import java.io.*;
    public class snow{
    public static void main(String args[]){
        int c=0,b;
        System.out.print("Please enter v of c:");
        try{
            c=(int)System.in.read();
    }catch(IOException e){};
            b=c+18;
        System.out.print("b="+b);
    }
    }
      

  5.   

    返回的是一个ASCLL码对应的 数字啊
    我输入4 
    结果B=70 输入5 B=71 
    有没有其他办法(除了将C减去0所对应ASCLL码序号)
      

  6.   

    import java.io.*;
    public class snow {
      public static void main(String args[]) throws IOException {
        int d,b;
        String c;
        BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Please enter v of c:");
        c=keyin.readLine();  \\这里可输入多个数(其实是字符)
        d=Integer.parseInt(c);
        b=d+18;
        System.out.println("b="+b);
      }
    }
    这样应该就没有问题了