调用String.getBytes(),在把每个byte强制转成int打出来,就是ASCII码了

解决方案 »

  1.   

    byte[] wux="obtain this string' code".getBytes();
    for(int i=0;i<wux.length;i++){
      System.out.println(wux[i]);
    }
      

  2.   

    不转成int也可以,直接打出来就是了。
      

  3.   

    public class TestChar
    {
        public static void main(String[] args)
        {
            String t = "this is a test for ASCII code!";
            for(int i=0;i<t.length();i++)
            {
                int ascii=t.charAt(i);
                System.out.println(t.charAt(i)+"<--->"+ascii);
            }
        }}
      

  4.   

    输出:
    t<--->116
    h<--->104
    i<--->105
    s<--->115
     <--->32
    i<--->105
    s<--->115
     <--->32
    a<--->97
     <--->32
    t<--->116
    e<--->101
    s<--->115
    t<--->116
     <--->32
    f<--->102
    o<--->111
    r<--->114
     <--->32
    A<--->65
    S<--->83
    C<--->67
    I<--->73
    I<--->73
     <--->32
    c<--->99
    o<--->111
    d<--->100
    e<--->101
    !<--->33
      

  5.   

    scbb(星际Baby)和 amjn(神雕过儿) 的做法都是错误的。
    楼主不要被误导了。
      

  6.   

    agree有空多看看java的api,可以学到很多的。
      

  7.   

    谢谢各位,尤其是“ feiyuegaoshan(飞跃) ”
      

  8.   

    agree feiyuegaoshan(飞跃) 楼主有空多看看java的api,可以学到很多的。