GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

why the code isn't executing

class Test 
{
    void m1()
    {int a=0,b=1,c=0,d=0;
int i=10;
for (d=0;d<i;d++)
{c=a+b;
a=b;
b=c;
System.out.println("sum"+c);
}
static void m2()
        {
    int a=0,b=1,c=0,d=0;
int i=10;
for (d=0;d<i;d++)
{c=a+b;
a=b;
b=c;
System.out.println("sum"+c);
}
    }
    public static void main(String[] args) 
    {
        Test t=new Test();
        t.m1();
        Test.m2();

    }
}

asked Dec 24, 2016 by anonymous

1 Answer

class Test 
{
    void m1()
    {
        int a=0,b=1,c=0,d=0;
        int i=10;
        for (d=0;d<i;d++)
        {
            c=a+b;
            a=b;
            b=c;
            System.out.println("sum"+c);    
        }
    }
    static void m2()
        {
            int a=0,b=1,c=0,d=0;
            int i=10;
            for (d=0;d<i;d++)
            {
                c=a+b;
                a=b;
                b=c;
                System.out.println("sum"+c);
            }
        }
        public static void main(String[] args) 
        {
        Test t=new Test();
        t.m1();
        Test.m2();
    }
}

There was a Syntax Error because You did not close the m1() function before declaring m2() function.

I have corrected it. Now it is Working .

answered Dec 24, 2016 by mohdanishh
reshown Mar 30, 2017 by Shubham Baranwal 1
...