There are two errors in the following JAVA program:
  static void g(int i){
   if(i==1){return;}
   if(i%2==0){g(i/2);return;}
   else {g(3*i);return;}
   }
  
please correct them to make sure we can get the printed-out result as below:
3 10 5 16 8 4 2 1

解决方案 »

  1.   

    System.out.println("3 10 5 16 8 4 2 1");
      

  2.   

    static void g(int i){
         System.out.pritnln(i);
       if(i==1){return;}
       if(i%2==0){g(i/2);return;}
       else {g(3*i+1);return;}
       }
    把3当参数传进去就是你要的结果
      

  3.   

    static void g(int i){
    System.out.println(i + " ");
       if(i==1){return;}
       if(i%2==0){g(i/2);return;}
       else {g(3*i +1);return;}
       }
      

  4.   

    也没有System.out.println();怎么打印出来地阿!!!
      

  5.   

    007JavaKing(猛将兄) ( :的正解
      

  6.   

    HOHO,cool cool,太cool了。007JavaKing(猛将兄) 太cool了。还有一种解法,大家看了不要喷啊System.out.println("3 10 5 16 8 4 2 1");
    return;HOHO,
      

  7.   

    gemouzhi(gemouzhi)兄:我们不喷,nokia的HR要喷了:)
      

  8.   

    恩。我还真想去nokia,可是nokia基本都是要男的,女的能面一些测试人员之类。叫nokia的HR去喷吧,HOHO。
      

  9.   

    class Nokia{

    public static void main(String[] args){static void g(int i){
         System.out.pritnln(i);
       if(i==1){return;}
       if(i%2==0){g(i/2);return;}
       else {g(3*i+1);return;}
       }
     }
    }
    编译好多错误!!
    我是新手 
    请教
      

  10.   

    sorry
    可以了
    class Nokia{
    static void g(int i){
     System.out.println(i);
     if(i==1) {return;}
     else if(i%2==0) {g(i/2);return;}
     else  {g(3*i+1);return;}
     }
    public static void main(String[] args){
    g(3);
    }
    }
      

  11.   

    帮忙给007JavaKing(猛将兄) 的程序加下注释谢谢
      

  12.   

    static void g(int i){
    System.out.print(i + " ");
       if(i==1){return;}
       if(i%2==0){g(i/2);return;}
       else {g(3*i +1);return;}
       }
    本人是新手,碰巧刚学了java,多多指教