0% found this document useful (0 votes)
13 views4 pages

Testi

The document discusses Java arrays and methods. It includes code snippets declaring and initializing different array types like integer, double, and nested arrays. Methods are defined to print arrays in reverse order, sum the major diagonal of a 2D array, eliminate duplicate elements from an integer array, and calculate a running sum by iterating from 1 to a given integer.

Uploaded by

ard ituad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Testi

The document discusses Java arrays and methods. It includes code snippets declaring and initializing different array types like integer, double, and nested arrays. Methods are defined to print arrays in reverse order, sum the major diagonal of a 2D array, eliminate duplicate elements from an integer array, and calculate a running sum by iterating from 1 to a given integer.

Uploaded by

ard ituad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

A) Vargu dueet te jete I renditur ne rend rrites

B.

public static void get(String[] args) {


double[] r = new double[100];

for (int i = 0 ; i< r.length; i++){


r[i] = Math.random() * 100;
}}

c.

double d[] = new double[30];

float f[] = {2.3, 4.5, 6.6};

d. double[] d = new double[5]

a.

public static void printo(){


int[][] array = {{1, 2}, {3, 4}, {5, 6}};

for(int i=array.length-1; i>=0; i--){

for(int j=array[i].length -1; j >=0; j--){

System.out.print( array[i][j]);
}
System.out.println();
}
}

b.po
c.E pasakte, mund te krijojme nje varg double dhe te vendosim vlera int.

3.

public static int[] eliminateDuplicates(int[] list){


int n = list.length;

if (n == 0) {
return new int[0];
}

Arrays.sort(list);

int uniqueCount = 1;
for (int i = 1; i < n; i++) {
if (list[i] != list[i - 1]) {
uniqueCount++;
}
}

int[] result = new int[uniqueCount];

result[0] = list[0];
int index = 1;
for (int i = 1; i < n; i++) {
if (list[i] != list[i - 1]) {
result[index++] = list[i];
}
}

return result;
}
int vargu[] = new int[10];
Scanner sc = new Scanner(System.in);

for(int i=0; i<10 ;i++){


vargu[i] = sc.nextInt();
}

int[] eliminoDuplicate = eliminateDuplicates(vargu);

for(int i=0; i<eliminoDuplicate.length; i++){


System.out.print(eliminoDuplicate[i] + " ");
}

4.

public static double sumMajorDiagonal(double[][] m){


double sum =0;
for(int i=0; i<m.length; i++){
sum += m[i][i];

}
return sum;
}

double s = sumMajorDiagonal(new double[][]{{1,2,3,4},{1,2,3,4},{1,2,3,4},


{1,2,3,4}});
System.out.println(s);

public static void calcSum(int i){

double sum =0;

for(int k=1; k<=i ;k++ ){


sum += (double)k/(k+1);
}
System.out.println(sum);
}
for(int i=1 ;i<=3; i++){
calcSum(i);
}

6.

a. Jo

b.extend superklasa

c.super() ose super(lista parametrave)

d.Trashigimia,Polimorfizmi, Enkapsulimi

You might also like