Skip to content

Instantly share code, notes, and snippets.

@nottux
Last active April 13, 2021 15:46
Show Gist options
  • Save nottux/36b059998cf74923b99108a3cb19e90c to your computer and use it in GitHub Desktop.
Save nottux/36b059998cf74923b99108a3cb19e90c to your computer and use it in GitHub Desktop.
package labtest;
import java.util.Arrays;
import java.util.Scanner;
public class labtest {
public static void reverse(double[] array){
//reading array from reverse
for (int i = array.length-1; i >= 0; i--) {
System.out.print(array[i] + " ");
}
}
public static int indexOfLargestElement(double[] array){
//we create varrible and put first element to it
double maximum_value = array[0];
int place_of_the_maximum_value = 0;
//go through the array and record the largest value
for (int i = 0; i < array.length; i++) {
if (maximum_value < array[i]) {
maximum_value = array[i];
// place_of_the_maximum_value=i++;
}
}
//recording the place of maximum value
for (int i = 0; i < array.length; i++) {
if (maximum_value == array[i]) {
place_of_the_maximum_value=i;
}
}
place_of_the_maximum_value=place_of_the_maximum_value++;
//still doesn't work properly
return place_of_the_maximum_value;
}
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
// input length of array , it can be hardcoded as 10
System.out.println("Enter the length of the input array:");
int length = s.nextInt();
double [] array = new double[length];
// entering the values
System.out.println("Enter the elements:");
for(int i=0; i<length; i++ ) {
array[i] = s.nextDouble();
}
// printing output
System.out.println("place of largest element is :");
System.out.println(indexOfLargestElement(array));
reverse(array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment