bleach_yy 2010-09-17 14:57
浏览 183
已采纳

为什么输入1234后输出的是6?

class LX5_3{

       public static void main(String[] args) throws java.io.IOException { 

         byte buffer[]=new byte[10]; 

         System.out.println("从键盘输入不超过10个字符,按回车键结束输入:"); 

         int count =System.in.read(buffer);//读取输入的字符并存放在缓冲区buffer中 

       System.out.println("保存在缓冲区buffer中元素的个数为:"+count); 

       System.out.println("buffer中各元素的值为:"); 

      for (int i=0;i<count;i++){ 

       System.out.print(" "+ buffer[i]);//在屏幕上显示buffer元素的值 

       } 

      System.out.println(); 

      System.out.println("输出buffer字符元素:"); 

      System.out.write(buffer, 0, buffer.length); 

       } 

      } 

为什么我输入1234后输出的是6?

package hh;

import java.util.*;
public class TestChuShi
{
public static void main(String[] args){
Father1 f = new Son1();
}

}
class Father1
{
static int i = 11;
static{
System.out.println("Father.static{}");

}
String str = "aaa";
{
    System.out.println(str);
}

Father1(){
    System.out.println("Father.constraction");
    getFun();
}
void getFun(){
    System.out.println("Father.getFun()");
}

}
class Son1 extends Father1
{
static int i = 22; ///下面3行是类的Father1的什么?
static{
System.out.println("Son.static{}");
}
String str = "bbb";
///下面3行是类的Father1的什么?
{
System.out.println(str);
}

Son1(String s){
    System.out.println(s);
}
Son1(){
    this("canshu");
    System.out.println("Son.constraction");
}
void getFun(){
    System.out.println("Son.getFun()");
}

}

  • 写回答

1条回答 默认 最新

  • iteye_14351 2010-09-17 15:25
    关注

    回车占两个字符,ASCII是13和10。所以你输入1234,会显示是6.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?