The perfect place for easy learning...

Java Programming Language

×

List of Programs


Java Practical Programs


Aim


Given an an array of integers, you are expected to find the minimum integer in the array then subtract the same from each element of the array and multiply each element wiht the same minimum integer and return the result.

Implementation


Java Program for finding minimum in an array then subtract and multiply the same minimum with each element.
import java.util.*;

public class ArrayMinSubMul {
	
	public static int[] actualTask(int[] input1) {
		List givenArray = new ArrayList();
		for(int value:input1)
			givenArray.add(value);
		
		int minimumValue = Collections.min(givenArray);
		
		for(int i = 0; i < input1.length; i++) {
			input1[i] = input1[i] - minimumValue;
			input1[i] = input1[i] * minimumValue;
		}
		
		return input1;
	}

	public static void main(String[] args) {

		int actualArray[] = { 5, 2, 7, 9, 8, 4, 1, 3 };
				
		
		int[] resultArray = ArrayMinSubMul.actualTask(actualArray);
		
		System.out.println("Final result:");
		for(int element:resultArray)
			System.out.print(element + " " );
	}
}

Result



   Download Source Code

Place your ad here
Place your ad here