请问各位怎样才能输出下面的算式:
1+2=3
2+3=5
3+5=8
5+8=13
用循环!急呀!!!

解决方案 »

  1.   

    1 2 3 5 8 13Fab数列 An = An-1 + An-2 (n>=2)就不写递归的了,估计你初学.//fab数列的非递归实现
    long f1 = 1L;
    long f2 = 1L;
    long f1_f2_sum = 0L;
    for (int i = 1; i <= 6; i++) {
    f1_f2_sum = f1 + f2;
    f1 = f2;
    f2 = f1_f2_sum;
    }
    System.out.println(f1_f2_sum);
      

  2.   


    public class xunhuan
    {
    public static void main(String args[])throws Exception
    {
       int  a,b,c;
       a=1;
       b=2;
       c=0;
       while(c<13){
       c=a+b;
       System.out.println(a+"+"+b+"="+c);
       a=b;
       b=c;
       }
    }
    }
      

  3.   

    哦 上边的throws Exception
    可以去掉
      

  4.   

    public class Function {
    public static void main(String[] agrs)
    {
    int a,b;
    a=1;
    b=2;
    for(int i=0;i<4;i++)
    {
    int temp=a+b;
    System.out.println(a+"+"+b+"="+temp);
    a=b;
    b=temp;
    }
    }
    }
      

  5.   

    class Test{
      public static void main(String args[]){
          int f=1,a=1,b=1;
          while(f<=5){
             b+=a;
             a=b-a;
             f++
             System.out.println(a+"+"+b+"="+(a+b)); 
          }
      }
    }
      

  6.   

    重新给你写下输出:public class fab {
        public static void main(String args[]) {
            long f1 = 1L;
    long f2 = 2L;
    long f1_f2_sum = 0L;
    for (int i=1; i<=4; i++) {
    f1_f2_sum = f1 + f2;
    System.out.println(f1 + "+" +f2 + "=" + f1_f2_sum);
    f1 = f2;
    f2 = f1_f2_sum;
    }
        }
    }
      

  7.   


    for(int i=1, j=2; i<=5;){
        System.out.println(String.valueOf(i)+"+"+
                    String.valueOf(j)+"="+(i+j));
        int tmp=i;
        i=j;j=tmp+j;
    }
      

  8.   

    int b,c,d;
     c=2;
     d=0;
    for(b=1;b<8;){
      d=b+c;
      System.out.println(b+"+"+c+"="+d);
      b=c;
      c=d;
    }
      

  9.   

    int b,c,d;
      c=2;
      d=0;
    for(b=1;b<8;){
      d=b+c;
      System.out.println(b+"+"+c+"="+d);
      b=c;
      c=d;
    }
      

  10.   

    class add
    {
    public add()
    {int s=2;
    for(int i=1;i<10;i++)
    {
    int a=i+s;
    System.out.println(i+"+"+s+"="+a);
    s=a;
      }
    }
    public static void main(String args[])
    {
    add a=new add();
    }
    }
    自己做的,应该可以
      

  11.   

    public class Fab{   public int[] creatFab{
         int[] intArray = new int[100];
         intArray[0] = 1;
         intArray[1] = 1
         for(int i = 2; i < n ;i++){
           intArray[i] = array[i-1] + array[i-2];
         }
         return intArray;
        }
       public static viod main(String[] arg){
           for(int i = 0;i<intArray.length;i++){
               System.out.println(intArray[i]);  
           }
       }  
    }
      

  12.   

    public class Fab{
        static public Long[] creatFab(){
         Long[] longArray = new Long[100];
         longArray[0] = 1L;
         longArray[1] = 1L;
         for(int i = 2; i < 100 ;i++){
           longArray[i] = longArray[i-1] + longArray[i-2];
         }
         return longArray;
        }
       public static void main(String[] arg){
           Long[] longArray = creatFab(); 
           for(int i = 0;i<longArray.length;i++){
               System.out.println(longArray[i]);  
           }
       }  
    }
    编译通过,运行正常。只是到92的时候由于数太大出现溢出。