package lab9;
public class Lab9 {
public static void main(String[] args) {
int x = (int)(Math.random()*100);
//populate(x);
int[] arr1 = {5,22,32,42,52};
int[] arr2 = {7,7,8,9,10};
printArray(arr1);
printArray(arr2);
printArray(difference(arr1, arr2));
}
public static int[] difference(int[] arr1,int[] arr2){
int[] arr3 = new int[5];
for (int i = 0; i < arr3.length; i++) {
arr3[i] = arr1[i] - arr2[i];
}
return arr3;
}
public static int lessThanZero(int[] arr){
int count = 0;
for(int x : arr)
if(x<0)
count++;
return count;
}
public static void populate(int length){
int[] arr = new int[length];
for (int i = 0; i < arr.length; i++) {
arr[i] = (int)(Math.random()*100);
}
System.out.println("Length = " + arr.length);
printArray(arr);
System.out.println("Min = " + min(arr));
}
public static int min(int[] arr){
int min = arr[0];
for (int i = 1; i < arr.length; i++) {
if(min>arr[i])
min = arr[i];
}
return min;
}
public static void printArray(int[] arr){
for(int x: arr)
System.out.print(x + " , ");
System.out.println("");
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.