java中System.out.println()中打印出来的是换行,还是回车+换行。
我在杭州电子科技大学做题时,我试了很多格方式,总是遇到格式错误。class Main{
    int n = 10;
    public void process1(){        for(int i=0; i<n;++i)
            System.out.println(i);
    }    StringBuffer buf = new StringBuffer();
    public void process2(){         for(int i=0; i<n;++i)
            buf.append(i+"\n");
         System.out.println(buf);
    }
    public static void main(String args[]){
         proess1();
         proess2();
    }
}是不是调用process1()和process2()方法打印出来的结果有很细小的差异。因为用process1()能交上去,没有格式错误!

解决方案 »

  1.   

    这段程序编译通过不了,帮你改了一下
    记住,类名永远不要命名为Main,否则main方法将无法使用class TestMain {
    int n = 10; public void process1() { for (int i = 0; i < n; ++i)
    System.out.println(i);
    } StringBuffer buf = new StringBuffer(); public void process2() { for (int i = 0; i < n; ++i)
    buf.append(i + "\n");
    System.out.println(buf);
    } public static void main(String args[]) {
    TestMain t = new TestMain();
    t.process1();
    t.process2();
    }
    }
      

  2.   

    可以为Main吧class Main{ 
        static int n = 10; 
        public static void process1(){         for(int i=0; i <n;++i) 
                System.out.println(i); 
        }     static StringBuffer buf = new StringBuffer(); 
        public static void process2(){         for(int i=0; i <n;++i) 
                buf.append(i+"\n"); 
            System.out.println(buf); 
        } 
        public static void main(String args[]){ 
            process1(); 
            process2(); 
        } 

      

  3.   

    Windows 平台上输出的是 \r\n
    Linux 平台上输出的是 \n
      

  4.   

    Windows 沿用了英文打字机的模式,想想看英文打字机要换一行的话是不是得先将小车回到左边的最顶端(回车),然后齿轮再下移一格用于换行(换行)。
      

  5.   

    楼上是正解  要看你的系统 windows是\r\n
    linux是\n
      

  6.   

    hdoj上的原题目不是这个,这个是我发贴时写得,没有编译,也没记得在主方法中new 一个对象再调用方法,呵呵。
    to gesanri:
        类名可以是Main,跟方法没关系。hdoj上做题,用java语言实现的,必需都得把类名改为Main才能交上去。因为oj系统是运行Main这个类的。
    to bao110908
       到底就是三颗星的啊!我以为只有把文本写入文本文件里才加\r呢!谢谢大家,我把题贴出来,大家有兴趣的可以做一下。
      

  7.   

    欢迎参加——HDOJ2009公开赛——非原创(9月23、26) 
    公告:HDOJ 将于2010年正式推出月赛~ 
    公告:2009上海赛区“热身赛”题目已经添加到2985—2992~  
    素数回文
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 1821    Accepted Submission(s): 357
    Problem Description
    xiaoou33对既是素数又是回文的数特别感兴趣。比如说151既是素数又是个回文。现在xiaoou333想要你帮助他找出某个范围内的素数回文数,请你写个程序找出 a 跟b 之间满足条件的数。(5 <= a < b <= 100,000,000);  Input
    这里有许多组数据,每组包括两组数据a跟b。 
     Output
    对每一组数据,按从小到大输出a,b之间所有满足条件的素数回文数(包括a跟b)每组数据之后空一行。 
     Sample Input
    5 500
     Sample Output
    5
    7
    11
    101
    131
    151
    181
    191
    313
    353
    373
    383
     
      

  8.   

    跟平台有关,请看:Windows中Java中的回车与换行
      

  9.   

    你的程序不能通过编译啊  
    你的process1()和process2()都是非静态的方法
    而你在main中也没有创建Main的对象,那再静态的main主线程中你怎么调用这两个方法呢   所以要先创建类的是类对象   才能用方法::public class tMain {
    int n = 10; public void process1() { for (int i = 0; i < n; ++i)
    System.out.println(i);
    } StringBuffer buf = new StringBuffer(); public void process2() { for (int i = 0; i < n; ++i) {
    buf.append(i + "\n"); }
    System.out.println(buf); } public static void main(String args[]) {
    tMain t = new tMain();
    t.process1();
    t.process2();
    }
    }
      

  10.   

    up
    要么实例化一个对象,要么用static方法;
      

  11.   


    //编译并运行下列代码的结果是?
    public class Main {
    public static void main(String args) {
    System.out.println("Hello world");
    }
    }以前做过这么一个题目,被误导了