4o Ergastirio

APXIKH 1o Ergastirio 2o Ergastirio 3o Ergastirio 4o Ergastirio 5o Ergastirio 6o Ergastirio 7o Ergastirio Programma Exetastikis

Dis1

class Dis1{
   public static void main(String args[]) {
      int Dis1[][] = new int [3][];
  Dis1[0] = new int[1];
  Dis1[1] = new int[2];
  Dis1[2] = new int[3];

  int i, j, k = 0;

  for(i=0; i<3; i++)
  for(j=0; j<i+1; j++) {
    Dis1[i][j] = k;
    k++;
  }

  for(i=0;i<3; i++) {
  for(j=0;j<i+1; j++)
   System.out.println(Dis1[i][j] + " ");
     System.out.println();
 }
    }
}

Factorial

class Factorial  {
        //Synartisi ypologismou tou paragontikou
        int fact(int n)  {
 int result;

 if (n==1) return 1;
 result = fact(n-1)*n;
 return result;
        }
}

class Recursion {
        public static void main(String args[]) {
 Factorial f = new Factorial();

 System.out.println("Factorial of 3 is "+ f.fact(3));
 System.out.println("Factorial of 4 is "+ f.fact(4));
 System.out.println("Factorial of 5 is "+ f.fact(5));
        }
}

4o Ergastirio

class Outer {
        int outer_x = 100;

        void test()  {
 Inner inner = new Inner();
 inner.display();
        }

        //H inner-class
        class Inner {
 void display() {
         System.out.println("display: outer_x = " + outer_x);
 }
        }
}

class InnerClassDemo  {
        public static void main(String args[]) {
 Outer outer = new Outer();
 outer.test();
        }
}