Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

book of tasks on programming, list, промежуточный, критерий, address, for, core, перемещение минимального элемента, processor, shr, обзор, математика
 

for valuable work you must have JavaScript (allow active content)

Java. J.20. Nest of tasks. Exceptions

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.1     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int m;
    try {
        for (int i=1; i<5; i++)
            for (int j=1; j<5; j++)
                {
                    m=i/(i-j);
                }
        }
    catch (RuntimeException r) {
        s+=1;
    }
    finally {
        s=s*2;
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.2     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int m;
    for (int i=1; i<5; i++)
        for (int j=1; j<5; j++)
        {
            try
            {
                m=i/(i-j);
            }
            catch (RuntimeException r) {
                s+=1;
            }
            finally {
                s=s+2;
            }
        }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.3     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int m;
    for (int i=1; i<5; i++)
        for (int j=1; j<5; j++)
        {
            try
            {
                m=i/(i-j);
            }
            catch (RuntimeException r) {
                s+=1;
            }
        }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.4     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int m;
    for (int i=1; i<4; i++)
        for (int j=1; j<4; j++)
        {
            try
            {
                m=i-j;
                if (m<0) m=0;
                s+=i % m;
            }
            catch (RuntimeException r) {
                s+=i;
            }
        }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.5     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int m;
    for (int i=1; i<4; i++)
        for (int j=i; j<4; j++)
        {
            try
            {
                m=i-j;
                if (m<0) m=0;
                s+=i % m;
            }
            catch (RuntimeException r) {
                s+=i;
            }
        }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.6     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int j=0;
    int[] m = new int[6];
    boolean Pr=true;
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    while (Pr)
    {
        try
        {
            Pr=false;
            for (int i=0; i<6; i++)
            {
                j=i;
                s+=10 / m[i];
            }
        }
        catch (ArithmeticException r) {
            s=s*2;
            m[j]=1;
            Pr=true;
        }
    }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.7     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int[] m = new int[6];
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    try
    {
        for (int i=0; i<6; i++)
        {
            s+=10 / m[i];
        }
    }
    catch (ArithmeticException r) { }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.8     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int[] m = new int[6];
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    for (int i=0; i<6; i++) try
    {
        s+=10 / m[i];
    }
    catch (ArithmeticException r) { }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.9     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int[] m = new int[6];
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    for (int i=0; i<9; i++) try
    {
        s+=10 / m[i];
    }
    catch (ArithmeticException r) { s-=1; }
    catch (IndexOutOfBoundsException r) { s-=2; }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.10     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int[] m = new int[6];
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    for (int i=0; i<9; i++) try
    {
        s+=10 / m[i];
    }
    catch (ArithmeticException r) { s-=1; }
    catch (IndexOutOfBoundsException r) { break; }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.11     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    int[] m = new int[6];
    m[0]=3;    m[1]=7;    m[2]=0;
    m[3]=4;    m[4]=0;    m[5]=9;
    for (int i=0; i<9; i++) try
    {
        s+=10 / m[i];
    }
    catch (ArithmeticException r) { continue; }
    catch (IndexOutOfBoundsException r) { s-=1; }
    return s;
}


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.20.12     Answer

Determine a value produced by function AA


int AA()
{
    int s=0;
    try
    {
        int k=-2;
        int[] m = new int[k];
    }
    catch (NegativeArraySizeException r) { s=1; }
    return s;
}

 

©   Aliaksandr Prykhodzka    1993 - 2007