Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

mod, interrupt, транслятор, stack, editor, шейкерный метод, site, метод пузырьков, not, десятичный, in, editor, manuel de programmation, критерий, shl
 

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

Java. J.11. Nest of tasks. Arrays

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.1     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int i = 0; i < moon.length; i++) moon[i]=i;
      for (int i = 5; i < 8; i++) moon[i]=moon[i] % 2;
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.2     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int k = 0; k < moon.length; k++) moon[k]=11-k;
      for (int k = 1; k < moon.length; k++) moon[k]=moon[k]*k;
      for (int k = 1; k < 6; k++)
      {
            int n1=k*2-1;
            int n2=k*2;
            int m=moon[n1];
            moon[n1]=moon[n2];
            moon[n2]=m;
      }
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.3     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int k = 0; k < moon.length; k++) moon[k]=1;
      for (int k = 1; k < 4; k++)
      {
            int n=k*3-2;
            moon[n]=2;
      }
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.4     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      int n;
      for (int k = 1; k < 4; k++)
      {
            n=k*3-2;
            moon[n]=1;
      }
      for (int k = 1; k < 4; k++)
      {
            n=k*3-1;
            moon[n]=2;
      }
      for (int k = 1; k < 4; k++)
      {
            n=k*3;
            moon[n]=3;
      }
      moon[4]=4;
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.5     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int i = 1; i < moon.length; i++) moon[i]=i*3-2;
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.6     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int i = 1; i < moon.length; i++) moon[i]=i;
      for (int i = 1; i < 4; i++)
            for (int j = i; j < i*3+1; j++) moon[i]=moon[i]+moon[j];
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.7     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


int[] AA()
{
      int[] moon = new int[11];
      for (int i = 1; i < moon.length; i++) moon[i]=i+(i % 4);
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.8     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


boolean[] AA()
{
      boolean[] moon = new boolean[11];
      for (int i = 1; i < moon.length; i++) moon[i]=(i % 3 == 1);
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.9     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


boolean[] AA()
{
      boolean[] moon = new boolean[11];
      for (int i = 1; i < moon.length; i++) moon[i]=(i % 2 == 1);
      for (int i = 1; i < 6; i++) moon[i+5]=!moon[i];
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.10     Answer      Pascal-analogue      Visual Basic-analogue

Determine values of first, second, third and fourth elements of array returned by function AA


boolean[] AA()
{
      boolean[] moon = new boolean[11];
      int k;
      for (int i = 1; i < 6; i++)
      {
            k=2*i-1;
            moon[k]=false;
            k=2*i;
            moon[k]=true;
      }
      for (int i = 1; i < 11; i++) moon[i]=moon[i] & (i % 3 == 0);
      return moon;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.11     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int[] k = new int[6];
      for (int i=1; i<6; i++) k[i]=i;
      for (int i=1; i<5; i++) k[i]+=k[i+1];
      int man=0;
      for (int i=1; i<6; i++) man+=k[i];
      return man;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.12     Answer      Pascal-analogue      Visual Basic-analogue

Determine a value produced by function AA


int AA()
{
      int Man=0, J=10;
      for (int I=1; I<5; I++)
      {
            if (I % 2 == 0) J=J-2;
            else J+=1;
            Man+=J;
      }
      return Man;
}

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

J.11.13     Answer      Pascal-analogue      Visual Basic-analogue

Determine the content of array produced by function AA


int[] AA()
{
      int[] Tiger=new int[5];
      Tiger[1]=5;      Tiger[2]=3;
      Tiger[3]=10;      Tiger[4]=8;
      for (int I=1; I<4; I++)
            for (int J=1; J             {
                  int M=J+1;
                  if (Tiger[J]>Tiger[M])
                  {
                        int KKK;
                        KKK=Tiger[J];
                        Tiger[J]=Tiger[M];
                        Tiger[M]=KKK;
                  }
            }
      return Tiger;
}

 

©   Aliaksandr Prykhodzka    1993 - 2007