Write a java program to read an array of positive numbers. The program should find the difference between the alternate numbers in the array and find the index position of the smallest element with largest difference. If more than one pair has the same largest difference consider the first occurrence.

Answers

Answer 1

Answer:

int s;

int[] num= new int[s];

Scanner sc = new Scanner(System.in);

System.out.printIn("Enter array size");

size = sc.nextInt();

for (i = 0; i < s; i++){

   num[i] = sc.nextInt();

}

int[] difference;

int count = 0;

for (i = 0; i < num.length(); i= i + 2){

   if (num[i] > num[i+1]){

       difference[count] = num[i] -num[i+1];

   }else{

       difference = num[i+1] - num[i];

   }

}

int max = 0;

for (int i : difference) {

   if ( i > max){

       max = i;

   }

}

int result = Arrays.stream(difference).boxed().collect(Collectors.toList().indexOf(max);

System.out.printIn(result);

Explanation:

The Java source code uses procedural method to execute a task. The program prompts for user inputs for the array size and the items in the array. Assuming the array has an even length, the adjacent items of the array are subtracted and stored in another array called difference. The index of the maximum value of the difference array is printed on screen.


Related Questions

window is a very popular operating system becouse of its _ environment .​

Answers

Window is a vary popular operating system because of its runtime and compatible environment .
hope it help
Windows is perhaps the most popular operating system for personal computers globally. ... Windows is very popular because it is pre-loaded in majority of the new personal computers. Compatibility. A Windows PC is compatible with most software programs in the market
Other Questions
Which of the following forms of plant reproduction is likely to produce a new plant that is different from the parent plant? Which leadership theory states that the challenge facing leaders is first to analyze the situation and identify the most appropriate style of leadership and then to develop the capacity to be flexible enough to use different leadership styles as appropriate The area of a rectangle is represented by the expression 16m - 24. Which expression shows a factored version of the Area, one that shows the length and the width.A | 8(2m+3)B | 8(2+3m)C | 8(2-3m)D | 8(2m-3) Name of k.p sharma oli daughter Sexual reproduction is different from asexual reproduction in what way? Who are the Tuareg? Describe what makes this people group unique. why is the forest extended in the northern region of North America considered as an important natural resource HELPPPPPPPPPP Lol thankd Select all the angle measurements that are correctg=24,h=24,f=151,g=29,b=132,h=19 Hello everyone. I was wondering if any one here plays Fortnite? If so, if you would like to gift me the Aura skin in the item shop, it will really make my Christmas. I would love to play with you guys. My epic is Queen-_-Evie I will be accepting friend requests. If you are not able, I totally understand but have a Merry Christmas and a Happy New Year!! 2 Efetue: a) (+7) . (- 5) b) (-9) . (- 8) c)(-15) : (+5) d) (+125) : (+25)preciso disso pra agora If a small motor does 520 J of work to move a toy car 260 m in 3.0 seconds, how much power is being applied by the motor? In 1859, when Darwin published "On the Origin of Species by Natural Selection", which argument was he explaining? A) An explanation for the change in types of minerals in an area through ecologicalsuccession.B) The reasons for the loss of biodiversity on all habitats on Earth.C) An attempt to explain the structural similarities observed among diverse livingorganisms.D) The effect of carrying capacity on the size of population. Why would modern times require a new modern approach to theatrical dance I will give brainless to the first ancer What was unique about the Battle of New Orleans in the War of 1812?A. Andrew Jackson died during it.B. The United States lost the battleC. It occurred in January 1815, after the Treaty of Ghent that ended of the war.D. The U.S. surrendered the city to Britain after the battle.#2 Which conflict was called the "Second American Revolution" by President James Madison?A. The French and Indian WarB. The War of 1812C. The Battle of Lake ErieD. The Battle of New Orleans Describe a real-world example on how coordinate geometry is/can be used in the real-world. Then, create a sample question based on your example for the rest of your classmates to solve. Please help! Please only respond if you know. This question is for the people that have read this book. People who said no by Laura Scandiffio. I need to know the Social Justice issue in this book. (For example, economical, racial, gender equality) then give my 2 examples from the book that support that social injustice. which of the following sentences would most likely be the claim of an argumentative essay Which equation represents a line that passes through the two points in thetable? Dose y = 7.2x represent a proportional relationship, if so identify the constant of proportionality. If not, explain why not.